WordPress.org

Ready to get started?Download WordPress

Forums

Image crop doesn't work at exact or smaller than dimensions of thumbnail setting (8 posts)

  1. wlanni
    Member
    Posted 3 years ago #

    Hello,

    I'm trying to recreate a thumbnail for an image in the media gallery. My thumbnail setting is 200x200. When I try to recrop a thumbnail at exactly 200x200, or anything smaller, it does not work and I'm left with no thumbnail at all. Any size larger works.

    I can understand this for smaller images, but I don't understand why this doesn't work for recreating a thumbnail at exactly the same size as my settings. Does anyone have an idea on how to fix this?

  2. unifiedac
    Member
    Posted 3 years ago #

    When you crop an image in the Media Library, you are not altering the original file, just creating a cropped instance of it. What I found is if you are trying to insert a cropped image into an area larger than the cropped area size, it will revert to the larger/original image and not the cropped version.

    For example, if you are using the image to fill a DIV that is 250px wide and you have cropped the image to 200px wide, WordPress will somehow use the larger/original image to fill the 250 width.

    I use <?php the_post_thumbnail('large'); ?> and then use CSS to limit the size of the image I want. It loads the larger files and increases download time, but I needed the images to be displayed exactly as I cropped them, so it was a trade-off. I hope that helps.

  3. wlanni
    Member
    Posted 3 years ago #

    Hey thanks Unifiedac!

    Unfortunately, though your solution is very helpful in other circumstances (and actually resolves a similar question about some weird behavior I was seeing elsewhere), this doesn't quite answer my initial question: I was finding that using the image crop functionality to chop an image down to smaller than my thumbnail setting size wound up with no thumbnail being created at all -- I was winding up with no thumbnail image being created at all (I believe -- it's been a couple months and I think I worked around it).

    Anyway, thanks for your response, I seriously appreciate the contribution!!

  4. Jason Paul
    Member
    Posted 2 years ago #

    I've found that you really need to set the thumbnail size in the media settings in the dashboard to get a hard crop. Wish I could find a function to override but so far no luck.

  5. Lewis Vice
    Member
    Posted 2 years ago #

    I actually found a solution to the problem. There's a line of code within the media.php (located in wp-includes) which prohibits the creation of a thumbnail if the resulting image was the same or larger size.

    In WP 3.3.1 that code is located on line 380. The code you have to remove is:

    if ( $new_w >= $orig_w && $new_h >= $orig_h )
    	//	return false;

    Hope that helps.

  6. L D
    Member
    Posted 2 years ago #

    Bad idea to hack the core...

  7. Lewis Vice
    Member
    Posted 2 years ago #

    Well, I am a PHP noob and I don't know what other way to do it. Any suggestions on how to do it differently?

  8. L D
    Member
    Posted 2 years ago #

    Your way is technically right but the problem with changing core code is in the next update, all of that will be overwritten plus you never know if what you changed will introduce a security hole for your copy.

    It's unfortunate that the crop function in WordPress was never programmed very well to begin with. That's why some people have made plugins to provide a better cropping experience. If the plugins aren't available, I would suggest cropping the image the size you want and then uploading that instead. Those are really the only two ways to do it aside from building your own plugin. =/

    BTW, there is a crop plugin called TimThumb or something... can't remember the exact name... but from what I've read, there's a security hole with that (don't quote me on this, haven't used it before). ;)

Topic Closed

This topic has been closed to new replies.

About this Topic