• Resolved Daniel Alvares

    (@portuga_daniel)


    Hi,

    The plugin crops the image at center center, and I need it to crop at top center.

    Top center cropping works best with a huge variety of pictures, especially if people are in the photos because the heads is generally at the top.

    Is that possible?

    Tks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author nosilver4u

    (@nosilver4u)

    Imsanity isn’t supposed to crop images at all, unless you force it to (there’s a filter used for that). By default, Imsanity scales images, and any cropping is done by WordPress when generating the various thumbnails, as necessary.
    There are plugins you can use to adjust the cropping, like Theia Smart Thumbnails and this one: https://www.ads-software.com/plugins/my-eyes-are-up-here/

    Otherwise, there isn’t anything within Imsanity to adjust, as it uses the core resize function, which doesn’t have position parameters. That (WP_Image_Editor) class has a crop method with position parameters, but Imsanity never uses that, not even (like I mentioned above) when you force it to crop.

    Thread Starter Daniel Alvares

    (@portuga_daniel)

    I’m using the filter…

    So, I have to use another plugin to adjust the cropping position?

    Thread Starter Daniel Alvares

    (@portuga_daniel)

    I did some testing. None of those plugins adjust the position automatically on upload.

    Plugin Author nosilver4u

    (@nosilver4u)

    As you found, none of those plugins will affect the resizing of the original image, I was suggesting they could be used to adjust the cropping of the thumbnails, because at that point I didn’t realize you were using the filter to force Imsanity to crop the original.

    So I did some more research to see if it was possible to adjust the crop on the original, and it is. The value you return to the crop filter determines the way the resize function will crop. From the docs at https://developer.www.ads-software.com/reference/functions/image_resize_dimensions/

    1. If false (default), images will not be cropped.
    2. If an array in the form of array( x_crop_position, y_crop_position ):
    x_crop_position accepts ‘left’ ‘center’, or ‘right’.
    y_crop_position accepts ‘top’, ‘center’, or ‘bottom’. Images will be cropped to the specified dimensions within the defined crop area.
    3. If true, images will be cropped to the specified dimensions using center positions.

    If you want things cropped top-center, then you’d return this:
    array( ‘center’, ‘top’ )

    Thread Starter Daniel Alvares

    (@portuga_daniel)

    Tks nosilver4u.

    How do I enable this with the filter?

    Plugin Author nosilver4u

    (@nosilver4u)

    Depends a little upon how you’re using the filter currently, but normally it should be something like this:

    add_filter( 'imsanity_crop_image', 'imsanity_crop_position_custom' );
    function imsanity_crop_position_custom( $crop ) {
        return array( 'center', 'top' );
    }
    Thread Starter Daniel Alvares

    (@portuga_daniel)

    Thank you so much.

    It worked!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Adjust Crop to Top Center’ is closed to new replies.