• Resolved Twansparant

    (@twansparant)


    Hi there,

    I’m having some issues with generating the correct retina version of one of the following custom image sizes:

    add_image_size('portrait-lg', 946, 260, array('left', 'top') ); // desktop
    add_image_size('portrait-md', 768, 220, array('left', 'top') ); // tablets
    add_image_size('portrait-sm', 480, 220, array('left', 'top') ); // mobile

    According to the WordPress codex, I can add a crop position from which point the image should be cropped in the add_image_size function.

    The weird thing is, only the Retina version of the portrait-sm size doesn’t get cropped horizontally from the right, but is cropped from the center? The other 2 sizes arre cropped correctly from the right, both the normal as well as the retina versions?

    I tried deleting all the @2x versions, regenerated all my images again, nothing works.
    Think this could be some sort of bug maybe?

    The only workaround for now, is to manually replace the retina images that are not correctly cropped.

    Thanks!

    https://www.ads-software.com/plugins/wp-retina-2x/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Jordy Meow

    (@tigroumeow)

    I confirm there is a issue with cropping, I actually know about this from the beginning… but since there is some work to do for this I will do it a bit later. Please give me some time, this is really coming. It is the only feature missing in the core.

    Nicscott01

    (@nicscott01)

    Funny, I’ve been working on this and just figured out a way to fix this. Its actually pretty simple:

    Add an additional $crop parameter to wr2x_vt_resize.php:

    function wr2x_vt_resize( $file_path, $width, $height, $crop, $newfile )
    If crop = 1, make sure its a logical “true” (this may or may not be necessary). Otherwise, pass along the crop array. I added the following after line 18:

    if ($crop == '1') {
    			$crop_params = true;
    		}
    		else {
    			$crop_params = $crop;
    		}

    Pass $crop_params to the resize class:

    $image->resize( $width, $height, $crop_params );

    Then, in wp-retina-2x.php, after line 484 (before the foreach going through all the image sizes), initialize:

    global $_wp_additional_image_sizes;

    Edit the lines after the following comment to pass the crop info of the particular image size through to the wr2x_vt_resize() function:

    // Otherwise let's resize (if the original size is big enough).
    			else if ( $meta['sizes'][$name]['width'] * 2 <= $meta['width'] && $meta['sizes'][$name]['height'] * 2 <= $meta['height'] ) {
    				$image = wr2x_vt_resize( $originalfile, $meta['sizes'][$name]['width'] * 2,
    					$meta['sizes'][$name]['height'] * 2, $_wp_additional_image_sizes[$name]['crop'], $retina_file );
    			}

    I haven’t done extensive testing, but for one of the sites I’ve been working on, this works.
    Please roll this into the next version!

    Thanks for a great plugin, Jordy!

    Thread Starter Twansparant

    (@twansparant)

    Thanks @nicscott01
    Looks like you figured it out already! Great!

    Plugin Author Jordy Meow

    (@tigroumeow)

    Yes, it seems to work but you need to check this also:
    isset( $_wp_additional_image_sizes[$name] )

    I included this in the plugin. I will test it a bit more than release it ?? Did you try the code on your side Twansparant? If not, I can send you a beta version of the plugin for you to try, in that case please contact me directly and I will send it to you.

    Thread Starter Twansparant

    (@twansparant)

    Did you try the code on your side Twansparant?

    Not yet sorry, but I can today if you send the beta version.
    Thanks!

    Plugin Author Jordy Meow

    (@tigroumeow)

    It should work now ??

    @nicscott01 > Thank you very much. It helped with my bug (https://www.ads-software.com/support/topic/portfolio-on-ipad-not-showing-all-entries)

    ??

    Regards
    Michel

    No prob! Thanks for rolling into the plugin, Jordy!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Issue with crop position’ is closed to new replies.