WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Thumbnail generation position (10 posts)

  1. Asitis
    Member
    Posted 3 years ago #

    Hello!
    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?

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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

  3. Asitis
    Member
    Posted 3 years ago #

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

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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.

  5. Asitis
    Member
    Posted 3 years ago #

    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.

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    http://core.trac.wordpress.org/browser/tags/3.0.1/wp-includes/media.php

    hmmm... is it in here?

    Handles all the image resizing

  7. Asitis
    Member
    Posted 3 years ago #

    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 );
  8. Asitis
    Member
    Posted 3 years ago #

    Alrighty, that wasn't all to hard. I found this; a good explanation for what I found; http://shailan.com/how-to-change-post-thumbnail-crop-position-in-wordpress/

    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! :)

  9. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    Good stuff!

  10. pealo86
    Member
    Posted 3 years ago #

    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 :(

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags