Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #22 from tamw-wnet/normalize_images
Browse files Browse the repository at this point in the history
check dimensions of enlargement and use npr resizer if appropriate
  • Loading branch information
jwcounts authored Nov 18, 2022
2 parents 416161a + 3775046 commit ff4edaa
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions classes/NPRAPIWordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,28 +336,34 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
// check the <enlargement> and then the crops, in this order "enlargement", "standard" if they don't exist, just get the image->src
if ( !empty( $image->enlargement ) ) {
$image_url = $image->enlargement->src;
} else {
if ( !empty( $image->crop ) && is_array( $image->crop ) ) {
}
if ( !empty( $image->crop ) && is_array( $image->crop ) ) {
foreach ( $image->crop as $crop ) {
if ( empty( $crop->type ) ) {
continue;
}
if ( 'enlargement' === $crop->type ) {
$image_url = $crop->src;
// sometimes enlargements are much larger than needed
if ( ( 1500 < $crop->height ) || ( 2000 < $crop->width ) ){
// if there's no querystring already, add s=6 which media.npr.org resizes to a usable but large size
if ( strpos( $image_url, "?" ) === false ) {
$image_url .= "?s=6";
}
}
}
}
if ( empty( $image_url ) ) {
foreach ( $image->crop as $crop ) {
if ( empty( $crop->type ) ) {
continue;
}
if ( 'enlargement' === $crop->type ) {
if ( 'standard' === $crop->type ) {
$image_url = $crop->src;
}
}
if ( empty( $image_url ) ) {
foreach ( $image->crop as $crop ) {
if ( empty( $crop->type ) ) {
continue;
}
if ( 'standard' === $crop->type ) {
$image_url = $crop->src;
}
}
}
}
}
}

if ( empty( $image_url ) && !empty( $image->src ) ) {
$image_url = $image->src;
Expand Down

0 comments on commit ff4edaa

Please sign in to comment.