diff --git a/classes/NPRAPIWordpress.php b/classes/NPRAPIWordpress.php index 8c7a706..8c2c6ec 100644 --- a/classes/NPRAPIWordpress.php +++ b/classes/NPRAPIWordpress.php @@ -336,28 +336,34 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) { // check the 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;