Skip to content

Commit

Permalink
Only push sizes onto the queue when they're smaller than the original
Browse files Browse the repository at this point in the history
  • Loading branch information
A5hleyRich committed Dec 14, 2016
1 parent ed98a38 commit 7194d6b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions includes/class-image-processing-queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ public function get_image( $post_id, $sizes, $attr = '' ) {
continue;
}

if ( self::is_size_larger_than_original( $post_id, $size ) ) {
continue;
}

$item = array(
'post_id' => $post_id,
'width' => $size[0],
Expand Down Expand Up @@ -210,6 +214,28 @@ public static function does_size_already_exist_for_image( $post_id, $size ) {
$size_name = self::get_size_name( $size );
return isset( $image_meta['sizes'][ $size_name ] );
}

/**
* Check if an image size is larger than the original.
*
* @param int $post_id Image ID.
* @param array $size array in format array(width,height,crop).
*
* @return bool
*/
public static function is_size_larger_than_original( $post_id, $size ) {
$image_meta = self::get_image_meta( $post_id );

if ( ! isset( $image_meta['width'] ) || ! isset( $image_meta['height'] ) ) {
return true;
}

if ( $size[0] > $image_meta['width'] || $size[1] > $image_meta['height'] ) {
return true;
}

return false;
}
}

}

0 comments on commit 7194d6b

Please sign in to comment.