0

In my child Theme I have set my custom image with add_image_size( 'big', 1500, 1000 ) I left out the crop parameter, but it is [false by default][1] anyway.

I want to make this a variable option.

I have just written a plugin that displays all the registered image sizes (including WP's thumbnail, medium and large sizes) plus my custom size.

With checkboxes I do update_option($_size."_crop", true) for WP's image sizes and global $_wp_additional_image_sizes; $_wp_additional_image_sizes[$_size]['crop'] = true for my custom size.

The thumbnail, medium and large work all fine but I can't get to override the default false $crop parameter from add_image_size? When I var_dump($_wp_additional_image_sizes;) on my plugin page the boolean displays true, but when I upload a new image it is like add_image_size() wins over my plugin?

When I set add_image_size( 'big', 1500, 1000, true) in functions.php everything works like I want, but I want to make it an option to switch between hard and soft cropping - from my plugin options page obviously.

0

OK I have found out a way to do this. With the plugin, with some checkboxes I am setting a crop option in the db in wp_options table, just like WP does it for the thumbnail, medium and large sizes.

So my big image sets the add_option('big_crop', true)

Than in functions.php I do:

if ( get_option( "big_crop" ) == true ) {
    add_image_size( 'big', 1500, 1000, true );  
} else {
    add_image_size( 'big', 1500, 1000, false ); 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.