Resize an image on width, then check its hight and resize again

See all posts Reply

Resize an image on width, then check its hight and resize again new!
by Mike, 16 years, 4 months ago
Basically I am using image_src_x to verify that an image is set to 100px wide if it is larger than that.

I also want to set it to check to see if the image (once resized) is larger than 200px tall and take the current image and use 200px as a height to resize the image to (while keeping ratio).

Id this possibe to do before process() or do I have to go through, upload the image, then check it locally?Reply
Re: Resize an image on width, then check its hight and resize again new!
by colin, 16 years, 4 months ago
I am not sure I understand it all. But you can set the maximum width and height, and the class will resize it within these constraints. For instance:
$foo->image_ratio = true;
$foo->image_x = 100;
$foo->image_y = 200;

You can also try:
$foo->image_ratio_crop = true;
$foo->image_x = 100;
$foo->image_y = 200;
Reply
Re: Resize an image on width, then check its hight and resize again new!
by Mike, 16 years, 4 months ago
I have users uploading self taken images of beer bottles, so some of them may be 50px wide and 200px tall and others will be 100px wide and 400px tall etc...

So with your first example, will this take a 400x500 picture and make it 100x125? What if a 200x1000 picture was uploaded, I would like it to make this picture 40x200. Is that clearer?

If it is larger than 100 wide, I want it resize, but now it may be 100 wide AND 300 tall, I want to take this newly resized image and apply the 200px tall rule to make it like 66 x 200.

$foo->image_ratio = true;
$foo->image_x = 100;
$foo->image_y = 200;

What I am currently using is this
$handle = new upload($_FILES['beer']);
if ($handle->uploaded) {
  $handle->file_new_name_body   = $name;
  $handle->image_convert = 'jpg';
  // check that the image is less then 100 px wide
  if ($handle->image_src_x >= 100){
    $handle->image_resize         = true;
    $handle->image_x              = 100;
    $handle->image_ratio_y        = true;
  }
  $handle->file_auto_rename = false;
  $handle->file_overwrite = true;
  $handle->image_watermark = '/path/watermark.png';
  $handle->image_watermark_x = 5;
  $handle->image_watermark_y = 25;
  // where to upload the image
  $handle->process('/path/');
  if ($handle->processed) {
    $image=$beer . '.jpg';
    $sql="INSERT INTO xxxx VALUES ('$beer', '$image', etc....)";
    mysql_query($sql);
    $handle->clean();
    // now verify that it isnt taller than 200px.
    $handle = new upload('/path/'.$name.'.jpg');
    // check that the image is less then 200 pxtall
    if ($handle->image_src_y >= 200){
      $handle->image_resize         = true;
      $handle->image_y              = 200;
      $handle->image_ratio_x        = true;
    }
			
    $handle->file_auto_rename = false;
    $handle->file_overwrite = true;
    $handle->process('/home2/beerspot/public_html/beers/');
  } else {
    echo 'error : ' . $handle->error;
  }

So basically, it uploads, does all its stuff, then processes. After that I pull it back up and check the size again. I dont know if this is the clumsy way of doing it or the only way.. BTW, thanks for making a very nice product!Reply
Re: Resize an image on width, then check its hight and resize again new!
by colin, 16 years, 4 months ago
Try this:
$foo->image_ratio = true;
$foo->image_x = 100;
$foo->image_y = 200;

This will do what you describe at the start of your post. Try it, you will see.Reply