imagecopyresampled() (Features)

by Alfie ⌂ @, Vienna, Austria, Saturday, June 01, 2013, 14:42 (1636 days ago)

Hi,

currently an image is resized if

  • at least one dimension is larger then stated in the forum’s settings and/or
  • the filesize is larger then stated in the settings.

This has a drawback if an image is within the dimension limits but the file size is too large.
Example: max dimension 640px, max filesize 100KB.
If an image is 300px wide and its filesize is 101KB it will be upscaled to 640px – which might look awful. Does anybody have an idea how to avoid this, i.e., either reducing the quality while keeping the dimensions or downscaling to match the max filesize?

--
Best regards,
Alfie (Helmut Schütz)
BEBA-Forum (v1.8β)

Avatar

imagecopyresampled()

by Milo ⌂, Saturday, June 01, 2013, 16:12 (1636 days ago) @ Alfie

Hi,

This has a drawback if an image is within the dimension limits but the file size is too large.
Example: max dimension 640px, max filesize 100KB.
If an image is 300px wide and its filesize is 101KB it will be upscaled to 640px

I study the code and I can't confirm your description of the problem:

 
// get image size
$image_info = getimagesize($_FILES['probe']['tmp_name']);
$width=$image_info[0];
$height=$image_info[1];
 
// resize image, if it is too large
if($width > $settings['upload_max_img_width'] || $height > $settings['upload_max_img_height']) {}
 
// in your case, it is not to large, thus:
else
  {
    $new_width=$width;
    $new_height=$height;
  }
 
// calling resize_image-function to compress image
resize_image($_FILES['probe']['tmp_name'], $uploaded_images_path.$img_tmp_name, $new_width, $new_height, $compression)

regards
Micha

--
Surveyor-Software: Geodetic Network Adjustment & Deformation-Analysis and Transformation

imagecopyresampled()

by diglife, Saturday, June 15, 2013, 02:21 (1623 days ago) @ Alfie

[image]

RSS Feed of thread
powered by my little forum