Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If a particular image is uploaded with the same size dimensions or less than my set thumbnail size, wordpress won't auto cropped it. Doing some searching I come to learn that the hook responsible for this is located in the wp-includes/media.php file on line 364 as..

    // if the resulting image would be the same size or larger we don't want to resize it
if ( $new_w >= $orig_w && $new_h >= $orig_h )
    return false;

Deleting this line from the core file gives me the results I'm looking for by forcing wordpress to always create thumbnails. I was just wondering if there would be another way to to remove this function through the themes functions.php file rather than tampering with the core files?

Media.php function code

function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) {

if ($orig_w <= 0 || $orig_h <= 0)
    return false;
// at least one of dest_w or dest_h must be specific
if ($dest_w <= 0 && $dest_h <= 0)
    return false;

// plugins can use this to provide custom resize dimensions
$output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop );
if ( null !== $output )
    return $output;

if ( $crop ) {
    // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
    $aspect_ratio = $orig_w / $orig_h;
    $new_w = min($dest_w, $orig_w);
    $new_h = min($dest_h, $orig_h);

    if ( !$new_w ) {
        $new_w = intval($new_h * $aspect_ratio);
    }

    if ( !$new_h ) {
        $new_h = intval($new_w / $aspect_ratio);
    }

    $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);

    $crop_w = round($new_w / $size_ratio);
    $crop_h = round($new_h / $size_ratio);

    $s_x = floor( ($orig_w - $crop_w) / 2 );
    $s_y = floor( ($orig_h - $crop_h) / 2 );
} else {
    // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
    $crop_w = $orig_w;
    $crop_h = $orig_h;

    $s_x = 0;
    $s_y = 0;

    list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
}

// if the resulting image would be the same size or larger we don't want to resize it
if ( $new_w >= $orig_w && $new_h >= $orig_h )
    return false;

// the return array matches the parameters to imagecopyresampled()
// int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h ); }
share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.