WordPress.org

Forums

[resolved] add_image_size() & image_size_names_choose() help (3 posts)

  1. Christiaan Conover
    Member
    Posted 1 year ago #

    I'm trying to add a custom image size to my theme, but I'm running into trouble. First off, here is the code I've placed in functions.php:

    if( function_exists( 'add_image_size' ) ) {
    	add_image_size( 'extra-large', 1024, 1024 ); // Soft proportional crop mode.  Largest dimension no bigger than 1024px.
    }
    
    /**
     * Assign a human-readable name to custom image sizes for Media Library selection
     */
    function christiaanconover_custom_image_sizes( $sizes ) {
        return array_merge( $sizes, array(
            'extra-large' => __('Extra Large'),
        ) );
    }
    add_filter( 'image_size_names_choose', 'christiaanconover_custom_image_sizes' );

    I've activated the theme, and when I upload an image the only size I'm now offered to use is Full Size - all the default image sizes have disappeared. What am I missing? Do I need to add all the default image sizes to my image_size_names_choose function as well as my custom ones?

  2. bcworkz
    Member
    Posted 1 year ago #

    That's queer, you would not normally add default image sizes, they are almost hard coded into the insert media dialog, which is where I assume you are missing the default options?

    While they are hard coded, they are still filtered, so some plugin could disappear them. Check the global $wp_filter and see if there are any other callbacks hooked in, or just deactivate all plugins as an experiment.

    Another thing to check is if the uploads folders contain extra-large versions of the upload, assuming the upload original is larger, and the default sizes as well.

    You could also try tracing into the core function image_size_input_fields() and determine where the defaults disappear.

    I'm not sure what the problem is, but your code looks proper to me.

  3. Christiaan Conover
    Member
    Posted 1 year ago #

    Well, I knew it was something stupid and it turns out that's true. I just moved my site to a new server, and forgot to install php5-gd so no image resizing was being done - I just hadn't uploaded a photo until I tried to add the custom image size. I've installed gd and now all is right with the world :-)

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic