Image width resize

See all posts Reply

Image width resize new!
by joostvm, 15 years, 7 months ago
My image upload works, the images will upload in 2 folders, but the resize don't work's fine. The first uploaded image will have a width of 200px, the second image will have a width of 800. This is my code:

$handle = new Upload($_FILES['Filedata']);
if ($handle->uploaded) {
  $handle->image_resize            = true;
  $handle->image_x                 = 200;
  $handle->image_ratio_no_zoom_in = true;
  $handle->file_new_name_body = $_GET['nieuwsid'];
  $handle->Process($targetPath."klein/");
  
  // we now process the image a second time, with some other settings
  $handle->image_resize            = true;
  $handle->image_x                 = 800;
  $handle->image_ratio_no_zoom_in = true;
  $handle->file_new_name_body = $_GET['nieuwsid'];
  $handle->Process($targetPath."groot/");
        
  // we check if everything went OK
  if ($handle->processed) {
    echo '1';
  }
  $handle-> Clean();
}

But, my images are 100 and 150 or so pixels. When the image width is larger then 200 and/or 800, the image(s) must be resized, other the size must be original size.

How can I do this?Reply
Re: Image width resize new!
by colin, 15 years, 7 months ago
Using image_ratio_no_zoom_in should be doing what you want. If the image's width is smaller than 200px, then the image will not be resized. Isn't it what you want?

What are the dimension of the images that you are uploading? If it doesn't do what you want, can you copy here the log produced by the class?Reply
Re: Image width resize new!
by joostvm, 15 years, 7 months ago
The image before the upload is 2048 x 1536. When the upload is done, the first image should have a width of 200px, the second picture 800. When the upload is finished, both pictures are uploaded, but with a width of (must be 200) 150, and the second image (must be 800, right?) 200.Reply
Re: Image width resize new!
by colin, 15 years, 7 months ago
Can you copy here the log produced by the class?Reply
Re: Image width resize new!
by joostvm, 15 years, 7 months ago
Could you tell me how to make a log?Reply
Re: Image width resize new!
by colin, 15 years, 7 months ago
At the end, before calling clean();
echo $handle->log;
Reply
Re: Image width resize new!
by joostvm, 15 years, 7 months ago
Here's the log:

system information
- class version : 0.26
- GD version : 2.0.34
- supported image types : png jpg gif bmp
- open_basedir : /home/bluexs/:/tmp:/usr/local/lib/php/
- language : en_GB
source is an uploaded file
- upload OK
- file name OK
- MIME type detected as image/jpeg by UNIX file() command
- source variables
file_src_name : CIMG1845.JPG
file_src_name_body : CIMG1845
file_src_name_ext : jpg
file_src_pathname : /tmp/phpZsWhAc
file_src_mime : image/jpeg
file_src_size : 1287972 (max= 8388608)
file_src_error : 0
- source file is an image
image_src_x : 2048
image_src_y : 1536
image_src_pixels : 3145728
image_src_type : jpg
image_src_bits : 8
process file to /home/.../upload/nieuws/klein/
- file size OK
- file mime OK : image/jpeg
- new file name body : 66
- file name safe format
- destination variables
file_dst_path : /home/.../upload/nieuws/klein/
file_dst_name_body : 66
file_dst_name_ext : jpg
- image operation, keep extension
- checking for auto_rename
- destination file details
file_dst_name : 66.jpg
file_dst_pathname : /home/.../upload/nieuws/klein/66.jpg
- 66.jpg doesn't exist already
- image resizing or conversion wanted
- source image is JPEG
- setting destination file type to jpg
- resizing...
check x/y sizes
resized image object created
image_src_x y : 2048 x 1536
image_dst_x y : 200 x 150
- converting...
fills in transparency with default color
- saving image...
JPEG image created
image objects destroyed
- process OK
process file to /home/.../upload/nieuws/groot/
- file size OK
- file mime OK : image/jpeg
- new file name body : 66
- file name safe format
- destination variables
file_dst_path : /home/.../upload/nieuws/groot/
file_dst_name_body : 66
file_dst_name_ext : jpg
- image operation, keep extension
- checking for auto_rename
- destination file details
file_dst_name : 66.jpg
file_dst_pathname : /home/.../upload/nieuws/groot/66.jpg
- 66.jpg doesn't exist already
- image resizing or conversion wanted
- source image is JPEG
- setting destination file type to jpg
- resizing...
check x/y sizes
resized image object created
image_src_x y : 2048 x 1536
image_dst_x y : 200 x 150
- converting...
fills in transparency with default color
- saving image...
JPEG image created
image objects destroyed
- process OK
Reply
Re: Image width resize new!
by colin, 15 years, 7 months ago
Your image is being resized to fit within 150x150 by default. So if you set only image_x to be 200 (or 800) and not image_y, then image_y defaults to 150. So for the second process(), you are resizing within 800x150, and because your original image aspect, it ends up resizing into 200x150 to keep the ratio.

This is why your image is always being resized to an height of 150 pixels. Set image_y to be something (150 pixels, or 600 pixels, etc...) and it will work.

If you use image_ratio_no_zoom_xxx, you must set image_x and image_y.Reply
Re: Image width resize new!
by joostvm, 15 years, 7 months ago
Yeah, that seems to work fine! It's now: 800 width, 600 height, what meens: The image width will never higher then 800, and the height of the image will never be higher then 600? If so, great!Reply
Re: Image width resize new!
by colin, 15 years, 7 months ago
Yes, it is what it meansReply