Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check dimensions of enlargement and use npr resizer if appropriate #22

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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