• It appears that lots of people are having an issue with the crop feature of add_image_size. I have tried to diagnose my issue to no avail.

    I do have GD libraries installed, verified by phpinfo.

    From my functions.php:

    if ( function_exists( 'add_image_size' ) ) {
    		add_image_size( 'featured-mobile', 767, 900 );
    		add_image_size( 'featured-full', 1170, 500 ); //
    		}

    Original image is 2240 x 1867, so this would be a soft crop to 1170×500.

    From my page.php:

    <div class="featured-image-mobile visible-xs">
    	<?php if ( has_post_thumbnail()) {
    		the_post_thumbnail('featured-mobile');
    	}
    	else {
    	echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/featured-default.jpg" />';
    	}
    	?>
    </div><!--/.featured-image-mobile-->
    
    <div class="featured-image hidden-xs">
    	<?php if ( has_post_thumbnail()) {
    		the_post_thumbnail('featured-full');
    	}
    	else {
    	echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/featured-default.jpg" />';
    	}
    	?>
    </div><!--/.featured-image-->

    Here’s what I’ve tried:
    Regenerating Thumbnails
    Ensuring GD Library is installed on server

    Here is an imgur of what I’m seeing: http://imgur.com/Ktcp31y

    It should be full width 1170 soft crop to 500. Instead it is 599 x 500 (max height, no crop).

    What am I doing wrong here?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Original image is 2240 x 1867, so this would be a soft crop to 1170×500.

    Where do you get that from? I think your maths is a little off.
    2240 x 1867 has an aspect ratio of 1.99:1
    1170×500 has aspect ratio of 2.34:1

    Thread Starter imaginocracy

    (@imaginocracy)

    Hi esmi, thanks for the quick reply. Regarding aspect ratio, shouldn’t WP just take the original image, resize it to 1170×975 (correct aspect ratio) and crop the now 1170×975 image to 1170×500?

    It should work regardless right? Or am I wrong here?

    Hello, I’m also experiencing a similar issue, I just added some code to the init.php file in my roots theme installation:
    add_image_size('portfolio-530', 0, 530, true);

    I’m using the Regenerate Thumbnails plugin but it didn’t create the new image size (i have 717 images in my library). I even tried uploading a new version of an image, but the new size is still not there.

    Any ideas on what is happening here? When I was using WordPress 3.5.x this method would work without issue.

    Using WordPress 3.8.1 and Regenerate Thumbnails version 2.2.4

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    @chrsc, If your issue is regarding that plugin you need to post in its support section: http://wordpress.org/support/plugin/regenerate-thumbnails#postform

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    @imaginocracy, what did you originally use before add_image_size ?

    Thanks, I have now if anyone wants to follow it:

    http://wordpress.org/support/topic/add_image_size-function-not-working

    Thread Starter imaginocracy

    (@imaginocracy)

    Hi Andrew,

    I was sizing all my featured images myself prior to uploading to the correct size, but that will not be convenient for my client, so we’d like to use a custom size.

    Thread Starter imaginocracy

    (@imaginocracy)

    add_action( 'after_setup_theme', 'my_image_sizes' );
    
    function my_image_sizes() {
    	add_image_size( 'mobile', 767, 600, true );
    	add_image_size( 'desktop', 1170, 500, true );
    }

    The answer was to call this after_setup_theme, and changing the value to ‘true’ because by default it only fits to smallest x,y parameter.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘add_image_size problem’ is closed to new replies.