Reply to Re: Problem with rezising images ...

Re: Problem with rezising images ... new!
by Stefan, 15 years, 6 months ago
Colin and Dave ...
I got it working now ...
You can check my code pls give comments if I do something stupid
or it can be done in a better way ...

Anyway, I have uploaded an original image of 400x495 and this code
crop out 4 new images: 49x48, 128x128, 256x256 and 400x400

I use a form where I drag a square over the original to select the are I want in the cropped images, and now it works fine, just as I want it ...

I just want to know if I did it in a correct way or if it can be done better???

BTW Colin: I sent u a donation a few hrs ago for a license :)

$max_width  = "400";
$max_height = "400";
$upload_path = get_profile_image_path($id, $typ, "");
$fname_original = $upload_path."/".$fname;
list($original_width, $original_height, $type, $attr) = getimagesize($fname_original);
$arr_size[] = "400";
$arr_size[] = "256";
$arr_size[] = "128";
$arr_size[] = "048";
$n = count($arr_size);

for ($i=0; $i<$n; $i++) {

 // T R B L
 $top     = $input_top;
 $right   = $original_width - $input_left - $input_width;
 $bottom  = $original_height - $input_height - $input_top;
 $left    = $input_left;
 $file_new_name_body = "pic".$arr_size[$i]."px";

 // Start Step 1 - Crop
 $ul_handle = new upload($fname_original);  
 if ($ul_handle->uploaded) {
  $ul_handle->image_x             = $arr_size[$i];
  $ul_handle->image_y             = $arr_size[$i];
  $ul_handle->jpeg_quality        = 80;
  $ul_handle->file_overwrite      = true;
  $ul_handle->file_auto_rename    = false;
  $ul_handle->image_ratio_crop    = true;
  $ul_handle->file_new_name_body  = $file_new_name_body;
  $ul_handle->image_crop          = array($top, $right, $bottom, $left);  // T R B L
  $ul_handle->Process($upload_path);  
 }
 // End Step 1 - Crop

 // Start Step 2 - Resize
 $ul_handle = new upload($upload_path."/".$file_new_name_body.".jpg"); 
 if ($ul_handle->uploaded) {
  $ul_handle->jpeg_quality        = 80;
  $ul_handle->image_resize        = true;
  $ul_handle->file_overwrite      = true;
  $ul_handle->file_auto_rename    = false;
  $ul_handle->image_ratio_y       = true;
  $ul_handle->image_x             = $arr_size[$i];
  $ul_handle->file_new_name_body  = $file_new_name_body;
  $ul_handle->Process($upload_path); 
 }
 // End Step 2 - Resize
}
Reply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important