I bought a WP-Theme which defines a custom image-size in his theme-functions.php like this:
if ( function_exists( 'add_image_size' ) ){
add_image_size( 'tie-small', 70, 70, true );
}
As you can see the third-parameter is true, which results in hard crop mode (see Wordpress Documentation for add_image_size). This mode isn't taking care of the proportions so some of my thumbnails are resized very badly. I did some tests and changing the crop-Parameter to FALSE will create better results.
I want to overwrite this image-size by using a plugin so that I can update my theme without changing the value above to FALSE on every update. The add_image_size function storing his data in a array with $name as key. So multiplice calls of this function will overwrite the values up to the last call.
My plugin is very simple and looks like the following:
class My_Plugin {
public function __construct() {
add_action( 'after_setup_theme', array( $this, 'overwrite_wptheme_settings' ) );
}
public function overwrite_wptheme_settings() {
add_image_size( 'tie-small', 70, 70, false );
}
}
Its not working, I reuploaded a test-image and it looks like crop is set to true. I cant figure out why because the value was overwritten! I could verify this by going to the function tie_last_posts in the theme-functions.php of the theme. This function is generating the widget with the post-thumbnail image:
[...]
function tie_last_posts($numberOfPosts = 5 , $thumb = true) {
// [...]
<?php global $_wp_additional_image_sizes;
var_dump($_wp_additional_image_sizes);
?>
<?php the_post_thumbnail( 'tie-small' ) ; ?>
This will output the following before the widget:
array(3) {
["tie-small"]=>
array(3) {
["width"]=>
int(70)
["height"]=>
int(70)
["crop"]=>
bool(false)
}
["tie-large"]=>
array(3) {
["width"]=>
int(300)
["height"]=>
int(160)
["crop"]=>
bool(true)
}
["slider"]=>
array(3) {
["width"]=>
int(620)
["height"]=>
int(330)
["crop"]=>
bool(true)
}
}
As you can see, the attribute crop is set to false in the index tie-small. So it was overwritten by my plugin. But the thumbnail get cropped. I verified this by using a testimage which is getting clearly bad when it gets cropped by wordpress. I always reuploaded the image in the article. AND I have verified that the overwriting itself is working: I inserted add_image_size( 'tie-small', 70, 70, false ); at the end of the theme-functions.php and it worked, but in my plugin it isnt. Whats wrong here?