Problems with Resizing

See all posts Reply

Problems with Resizing new!
by Martina, 9 years, 7 months ago
hi,

i want to load an image and save it in two versions:

original load image: 620x414 pixel

version1: only height should be crop:
$handle->file_new_name_body = "620x280"
$handle->image_resize = false;
$handle->image_ratio_y = false;
$target_height = 280;
if($handle->image_src_y > target_height) {
  $padding = round (($handle->image_src_y - target_height) / 2);
  $handle->image_precrop = "$padding 0 $padding 0";
}        
$handle->Process($filedir);

version2: resizing image and height should be crop:
$handle->file_new_name_body = "300x160";
$handle->image_resize = true;
$handle->image_ratio_y = true;    
$handle->image_x = 300;            
$target_height = 160;
if($handle->image_src_y > $target_height) {
  $padding = round (($handle->image_src_y - $target_height) / 2);
  $handle->image_precrop = "$padding 0 $padding 0";
}
$handle->Process($filedir); 
$handle->Clean();

My Problem:
Imagesize of Version 1 is correct but the height of Version 2 is too less - it is only 142 pixel - but it should be 160 pixel!!!
In the second version the $handle->image_src_y is only 280 pixel but he should take the original image height ...

The image base for the transformation should always be the uploaded original image - but how can i do this?

regrads,
martinaReply
Re: Problems with Resizing new!
by colin, 9 years, 7 months ago
Can't you just do like this?
$handle->file_new_name_body = "300x160";
$handle->image_resize = true;
$handle->image_ratio_crop = true;    
$handle->image_x = 300;            
$handle->image_y = 160;            
$handle->image_ratio_no_zoom_in = true;
$handle->Process($filedir); 
$handle->Clean();

This will result in an image exactly 300x160, except if the original image is smaller than that.Reply
Re: Problems with Resizing new!
by Martina, 9 years, 7 months ago
oh many thanks - that works!!!!!!

regards martinaReply