class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
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.
$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!
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.
What I am currently using is this
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!
This will do what you describe at the start of your post. Try it, you will see.