• Both of these tend to shrink the image and then crop it to the dimensions listed.

    What I want is to just crop out the center of the image at 475 x 310

    add_image_size( ‘test’, 475, 310, array( ‘center’, ‘center’ ) );
    add_image_size( ‘test2’, 475, 310, array( ‘center’, ‘center’ ) );

    BTW I’m using the regenerate-thumbnails plugin to recreate all the images after I make a new add_image_size() deceleration.

    What am I doing wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Are you using this code within a callback to the “after_setup_theme” action?

    You can try using true instead of the array argument. It shouldn’t make any difference, the arguments are equivalent. But who knows?

    Just in case there’s a glitch in the plugin, test your code with a fresh upload before deciding it’s not working.

    Thread Starter winchendonsprings

    (@winchendonsprings)

    @bcworkz thanks for the reply.

    add_image_size( ‘test’, 475, 310, array( ‘center’, ‘center’ ) );
    add_image_size( ‘test2’, 476, 311, TRUE );

    in my functions file, after after_setup_theme, I just get an image that has been scaled down to 475 or 476 and cropped at 310 or 311.

    What I want is the full size image I upload to be cropped at 475 or 476 by 310 or 311 and not scaled at all.

    I tested this with the regenerate thumbnail plugin and a fresh uploaded image.

    Moderator bcworkz

    (@bcworkz)

    Ah, I see. I guess “crop” does not mean what we thought it meant. We apparently need to get to the heart of calculating exactly what sizes to scale and crop to. This is through the “image_resize_dimensions” filter. Whatever dimensions your callback returns here will override whatever WP normally does. The problem is there is no information about image size name or file name, only current and target dimensions and the $crop argument.

    You can probably determine whether the current sizes are for your added size by just the target width and $crop argument. The output array conforms to parameters for imagecopyresampled(). Presumably without the image source and destination parameters.

    Coming up with the algorithms to take any size source image and crop to the right size could take some doing. I’m pretty sure this is the solution you are looking for, though I’m sure it’s not as simple as you would like.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Crop image without scaling or resizing with add_image_size()’ is closed to new replies.