add_image_size is scaling, even though crop is set to true

I am trying to crop a 1000 x 648 image to 400 x 400.
I use this code in functions.php

add_theme_support( 'post-thumbnails' );
add_image_size('shop-size', 400, 400, array(center,center) );
add_image_size('shop-size2', 401, 400, true );

then i go to the regenerate plugin and run it. While I run it I open up wp-content uploads to check out what’s going on.

I watch as it creates a 400×259 image that is scaled. The regenerate plugin even says it is going to do a 400×400 cropped to fit for shop-size, and then proceeds not to.

I checked if gd is loaded with this and it returns ‘gd loaded’

<?php if (extension_loaded('gd')) 
     { 
         echo "gd loaded"; 
     } else { 
         echo "not loaded"; 
} ?>

I also tried hooking it into after_theme_setup like this:

function add_custom_sizes() {
    add_image_size( 'map-size', 199, 199, array('center','center') );
    add_image_size('shop-size', 599, 599, array('center','center') );
    add_image_size('discover-size', 749, 620, array('center','center'));
    add_image_size( 'map-size1', 198, 199, true );
    add_image_size('shop-size1', 598, 599, true );
    add_image_size('discover-size1', 748, 620, true);
}

add_action('after_setup_theme','add_custom_sizes'); 

however as i regenerate it still makes a 198×165 instead of 198×199 (from 768 x 641)

The parent is called ‘rise’ by thrive themes. I contacted them but they said they don’t have support for dev questions.

The parent only uses add_image_size once, i tried removing this but I still had the scaling instead of cropping issue.

I’ve included the rise files below. I have a hunch they do some kind of custom scaling thing? And i will have to over-ride this some how?

thrive image optimization file – https://pastebin.com/1QEa6YJv
thrive functions – https://pastebin.com/pAqBt285

Can anyone help me figure out what i’m doing wrong? Thanks for any help.

3 Answers
3

from your question i under that you want fixed size cropped images when you upload image, why don’t you use wp_get_image_editor. I used it in my project where i wanted cropped images of fixed size so i did this code.

$path = $newPath['basedir'].'/newImgas/';
$cropfile = uniqid() . '.png';
$cropfilename = $path.$cropfile;
$cropImage = home_url(). '/wp-content/uploads/newImgas/'.$cropfile;
$c_image = wp_get_image_editor($newImage);
if ( ! is_wp_error($c_image) ) {
  $c_image->resize( 600, 600, TRUE);
  $c_image->save( $cropfilename );
}

You can find example here. Please reply me if it isn’t what you wanted.

Leave a Comment