Support » Plugins » Hacks » Thumbnail generation position

  • Resolved Asitis


    My site depends on the featured-thumb function, and I regenerate multiple sizes on different pages of one image.
    The problem is, WordPress generated thumbnails are always positioned in the middle of the image – it’s always the center part of a image as the thumbnail.
    Now I need the system to create thumbnails from the top-left part of the image.. How do I go about doing that?

Viewing 9 replies - 1 through 9 (of 9 total)
  • AFAIK, you can’t at this time…with the built in function.

    There may be other thumbnail options you can look into if you are interested

    Hm, I don’t mind modifying some core files if that’ll do the trick..?

    It might, but its a bad idea really….

    I’m not sure if you could do it with a function or plugin, I’ve never looked at the stuff.

    But I’m pretty sure anybody here would recommend you don’t touch core files.

    Simply put, you will lose your changes on a blog upgrade. And you have to upgrade for security if nothing else.

    I understand the consequences of doing such thing, I am a experienced webmaster for quite some years now.
    But AFAIK there is no function for it, nor plugin. And I DO know it’s easier to program to use the top left as starting point while cropping, so somewhere in the WordPress code there’s a line that defines to use something else then the topleft corner.
    I want to know where that is, so that I might write my own function for it – maybe a plugin.

    hmmm… is it in here?

    Handles all the image resizing

    Yes! There it is, now to figure out how it works (ahhh, math..!) (line 341)

    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 );

    Alrighty, that wasn’t all to hard. I found this; a good explanation for what I found;

    As it sais, this function isn’t pluggable.. but it’s a minor edit, of which there is no real problem if the edit gets reverted on an update, plus it’s easy to notice and change back after an update! 🙂

    Good stuff!

    I can’t believe it isn’t possible to achieve this without editing the core files! I really don’t like the idea of editing the core files so I may just have to stick with the centre cropping 🙁

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Thumbnail generation position’ is closed to new replies.