Josef Kuchař
Josef Kuchař

Reputation: 51

add_image_size with exact width + auto height, but the resized width is limited to a maximum value

I need a little help with resizing images in Wordpress. I want to set exact width of 956px to an image and floating height. I have tried this:

add_image_size('full_widthn', 956, 9999, TRUE);
add_image_size('full_widthn2', 956, 9999, false);
add_image_size('full_widthn3', 956, 9999);
add_image_size('full_widthn4', 956, 100, false);
add_image_size('full_widthn5', 956);

But the result of this code is this. (only 700px width)

enter image description here

The original resolution of the uploaded image is 1070px. Where could be a problem, please?

Upvotes: 4

Views: 6814

Answers (1)

FluffyKitten
FluffyKitten

Reputation: 14312

Fixed Width:

Somewhere in your theme, most likely in functions.php, $content_width is set to 700.

$content_width is a global variable used in themes to set the maximum allowed width for any content in that theme.

Your images are getting resized on upload to the size you specify, but the options you are shown in the Media Editor are adjusted to fit a maximum width that's limited by $content_width in your theme.

From the Wordpress Codex:

Notes: This variable is also used when displaying a pop-up selection in the Media Editor. If you have used the global $_wp_additional_image_sizes to allow a pop-up of your custom image sizes defined using add_image_size() then the $content_width will override the width specified by your add_image_size() function.

Auto height:

In relation to not having a fixed width height, Any of the following from your examples will result in a fixed width of 956px (unless the uploaded image is smaller) and auto height:

add_image_size('full_widthn2', 956, 9999, false);
add_image_size('full_widthn3', 956, 9999);
add_image_size('full_widthn5', 956, 0);
add_image_size('full_widthn5', 956);

Upvotes: 3

Related Questions