Keeping image size and filling background with color till the size i want

See all posts Reply

Keeping image size and filling background with color till the size i want new!
by Milen, 15 years, 9 months ago
I want to make image 200x200 but to keep original image size and ratio if image width is small than 150px ( and height is small than 150px) and place image in the middle of 200x200 and fill space till 200 (TBLR) with color background.

I can't make it to keep original image size and ratio!
if ($handle->image_src_y <= 150) {
  $handle->image_resize = true;
  $handle->image_ratio_fill = true;
  $handle->image_convert = 'jpg';
  $handle->image_x = 200;
  $handle->image_background_color = '#FF00FF';
  $handle->Process('./pictures/');
}

Sry for my English!
ThxReply
Re: Keeping image size and filling background with color till the size i want new!
by colin, 15 years, 9 months ago
There is no automatic way to do what you want.

However, starting wit hthe code that you have, you can use image_cropwith negative values in order to add "space" on the sides of the picture if the original picture is less than 200px wide.

So if the picture's width (or height) is less than 200px, you keep it as is, and calculate the space you need to add, and set a negative cropping value. If the image is 200px or wider, then you simply resize it using image_ratio_crop or image_ratio_fill.Reply
Re: Keeping image size and filling background with color till the size i want new!
by Milen, 15 years, 9 months ago
i manage to get what i want with negative values of image_crop.
Thank you!Reply