[resolved] Crop from LEFT or RIGHT of image instead of just center (3 posts)

  1. rk2oo9
    Posted 7 years ago #

    Hey Guys,

    Just thought I'd post this in case anyone wants to do the same on their blog.

    By default, WP crops a thumbnail from the CENTER of the image. I am creating a Web Design gallery and generally the left hand side of my screenshots contain the important bits (logos etc). So i wanted my thumbnails to be cropped from the LEFT (not Center). Here is what i did (im using WP v2.7)

    1) Go to wp-includes/media.php

    2) Go to Line 288

    3) Replace this:

    $s_x = floor(($orig_w - $crop_w)/2);

    with this:

    //$s_x = floor(($orig_w - $crop_w)/2); 
    $s_x = 0;

    (Commenting out the old code in case you want to center again later).

    Using $s_x = 0; just means that it is cropped from the LEFT. Alternatively, you can use $s_x = $orig_w - $crop_w; to crop from RIGHT. Oh and you can follow the same methodology to crop from TOP or BOTTOM.

    Hope it helps.



  2. bryan868
    Posted 6 years ago #

    I don't think this applies to 2.8, as it didn't work.

  3. Alexandre
    Posted 6 years ago #

    Is there a way to do this from my theme's functions.php?

    I don't want to mess with the WordPress installation as I'd have to modify it every time a new version came out...

    It also seems more elegant to do it through options in the theme, rather than hack WP includes.

    Any help is greatly appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic