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.

I want my thumbnails on a particular page to be 300px × 100px, exactly. Currently, images shrink until they hit the 300 pixel or 100 pixel mark. How do I get the image to crop to exactly 300 × 100 (preferably without image distortion).

// functions.php:
if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );

if ( function_exists( 'add_image_size' ) ) { 
    add_image_size( 'post-thumb', 620, 207, true );
    add_image_size( 'home-thumb', 220, 180, true );
    add_image_size( 'index-thumb', 300, 100, true );
}
// index.php:
if ( has_post_thumbnail()) the_post_thumbnail('index-thumb');
share|improve this question
    
The images that are shrinking must be the images that were uploaded before you specified these sizes? or you are having issues with newer uploads too? Because the true parameter actually crops the image with out distorting them. –  Hameedullah Khan Jan 23 '12 at 13:59
    
I have it set to true but the image does not crop to 300 by 100. Its crops to 300 by X pixels or to Y pixels by 100. Whichever comes first. –  pope Jan 23 '12 at 20:57
    
That is how WP crops, for the exact 300x100 crop, check the solution at: wpquestions.com/question/show/id/1098. NOTE:I haven't tested it myself. –  Hameedullah Khan Jan 24 '12 at 2:18
    
Been having the same issues, found this and its working for me - sumtips.com/2011/12/custom-image-sizes-in-wordpress.html –  user21362 Oct 11 '12 at 15:10
add comment

3 Answers

Try to Change the "ture" paramater to "false" . You can also remove the "if" statements on the functions php if they are not needed for something else...

share|improve this answer
    
The true parameter actually crops the image, if you will make it false the image will not be cropped, it will be resized instead. –  Hameedullah Khan Jan 23 '12 at 14:00
    
Marking it true or false gives me the same result. –  pope Jan 23 '12 at 15:27
    
did you made sure that your images are actually Bigger than sizes you defined as thumbs ? and did you try to remove the "if" clauses ?? –  krembo99 Jan 23 '12 at 16:47
    
I did try larger images. Same result. Removing the if clauses gives an error. –  pope Jan 23 '12 at 19:42
    
can you give the error ? –  krembo99 Jan 24 '12 at 13:37
add comment

Refer to the add_image_size() Codex entry:

<?php add_image_size( $name, $width, $height, $crop ); ?>

The $crop parameter is the key:

(boolean) (optional) Crop the image or not. False - Soft proportional crop mode ; True - Hard crop mode.

Default: false

That is:

  • False (default): box-resize - (resize image against the constraining dimension)
  • True: hard-crop - crop the image exactly to the specified dimensions

Thus your code should work:

// Add Theme support
add_theme_support( 'post-thumbnails' );

// Register custom image sizes
add_image_size( 'post-thumb', 620, 207, true );
add_image_size( 'home-thumb', 220, 180, true );
add_image_size( 'index-thumb', 300, 100, true );

If you find that your images are not being rendered/displayed properly, there are a couple of things to verify:

  • For images added prior to implementation of these custom image sizes, you will need to regenerate the thumbnails for those images
  • Image sizes will not be generated for images that are not at least as large as the specified dimensions of a given image size. Thus, ensure that your images are at least as large as your largest-specified hard-crop image size. (Box-resized images are not as constrained, and only need to be at least as large as the smallest dimension of a given image size.)
share|improve this answer
add comment

Take a look to this plugin

  • it creates unlimited image sizes (cropped and not)
  • it adds sizes on media select field
  • it adds css filtering and animations
  • it can manage watermarks
share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.