0

I am trying to create a square thumbnail with auto crop with size of 300px 300px. I only get the width of 300px but the height is auto, i think is not cropping.

I tried this:

add_image_size( 'custom_image_size', 300, 300, true );
the_post_thumbnail('custom_image_size'); 

and this

set_post_thumbnail_size( 300, 300, true ); 
the_post_thumbnail(); 

but i get the width 300px and the height is auto. I also tried to Regenerate Thumbnails by using a wordpress plugin. So what should i do to get the thumbnail 300px with 300px ?

Images have dimensions: 1600 × 1200... so the images are bigger then 300px in width and height.

  • 1
    What is height of the image that you have uploaded ? – Rohil_PHPBeginner Sep 25 '14 at 10:06
  • Confirm that the image you have uploaded is far more stretched than the 300 x 300px. – Mayeenul Islam Sep 25 '14 at 10:08
  • i just edit my post... every image is more stretched than the 300 x 300px. – Alex Sep 25 '14 at 11:15
0

As the two comments above said: The Uploaded Image has to be larger than 300px * 300px to get 300px * 300px at the end.

WordPress just scales down Images, but does not scale up Images.

0

You need to crop by height. I believe passing two values as 300 means WP will look what the most is that is can resize the image to before it exceeds 300px in either width of height. Try this (untested);

add_image_size( 'custom_image_size', 9999, 300, true );

As the others have said, your code won't work unless the original image is large enough to work with.

0

So i followed this link how-to-get-larger-images-in-a-wordpress-gallery and i changed the Thumbnail size to 300px with 300px from SETTINGS -> MEDIA, and then run a Regenerate Thumbnails. Now the thumbnails are ok by using the code

<?php the_post_thumbnail( array(300,300) ); ?>
  • That was a bit ironic :) – Alex Sep 25 '14 at 12:21
-1

The best solution for this is Timthumb(https://code.google.com/p/timthumb/) or you can check this post where they did something on fly and it's working also

https://wordpress.org/support/topic/add-image-size-doing-width-but-not-height-or-crop

  • if i am using the_post_thumbnail( array(150,150) ... the images are ok, square with 150px ... but if i increase to 300, then the height is auto. <img width="300" height="166" src="/wp-content/uploads/2014/09/4-300x166.jpg" class="attachment-300x300 wp-post-image" alt="4" /> – Alex Sep 25 '14 at 11:36
  • the_post_thumbnail( 'thumbnail' ); // Thumbnail (default 150px x 150px max) the_post_thumbnail( 'medium' ); // Medium resolution (default 300px x 300px max) because wordpress default image size as a thumbnail is 150 px, if you want 300px then you can use medium size but my suggestion is resize the images on the fly (timthumb is the best one) – Bimal Das Sep 25 '14 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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