Jump to content

Limitations and imagecopyresampled vs imagecopyresized


PEJAS

Recommended Posts

 

I have used the script below to upload and resize images.

 

I have noticed some kinde of LIMITATIONS...

 

• imagecopyresampled & imagecopyresized >>>

     - image size 3.638 x 3.139 px works fine but not 3.639 x 3.139 or 3.638 x 3.140 px

     - image size 3.874 x 2.996 px works fine but not 3.875 x 2.996 or 3.874 x 2.997 px

     - image size 3.335 x 3.335 px is the largest Square images possible to upload

     and all this is independent of filsize in kb

 

Is there any way to calculate the this limitations? As 3.874x2.996 > 3.638x3.139 this dosen't make any sense  :confused:

As I get the same result with both imagecopyresampled and imagecopyresized what are the real difference?

 

thanks for all help.

 

=== SCRIPT ================================================================

//Create image from file

$uploadedfile = $_FILES['file']['tmp_name'];

$src = imagecreatefromjpeg($uploadedfile);

 

// Set a maximum height and width

$newwidth = 1280;

$newwidth1 = 700;

$newwidth2 = 120;

$newheight = 1280;

$newheight1 = 700;

$newheight2 = 120;

 

// Get new dimensions

list($width,$height)=getimagesize($uploadedfile);

 

// Set imageratio

$ratio = $width/$height;

 

// Set new sizes

if ($newwidth/$newheight > $ratio) {

  $newwidth = $newheight*$ratio;

  $newwidth1 = $newheight1*$ratio;

  $newwidth2 = $newheight2*$ratio;

} else {

  $newheight = $newwidth/$ratio;

  $newheight1 = $newwidth1/$ratio;

  $newheight2 = $newwidth2/$ratio;

}

 

// Resample  Resize

$tmp = imagecreatetruecolor($newwidth, $newheight);

$tmp1= imagecreatetruecolor($newwidth1, $newheight1);

$tmp2= imagecreatetruecolor($newwidth2, $newheight2);

 

//imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

//imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);

//imagecopyresampled($tmp2,$src,0,0,0,0,$newwidth2,$newheight2,$width,$height);

 

imagecopyresized($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

imagecopyresized($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);

imagecopyresized($tmp2,$src,0,0,0,0,$newwidth2,$newheight2,$width,$height);

 

//Save  files to folders

$filename = "images/". $_FILES['file']['name'];

$filename1 = "images/small/". $_FILES['file']['name'];

$filename2 = "images/thumbnail/". $_FILES['file']['name'];

 

magejpeg($tmp,$filename,100);

imagejpeg($tmp1,$filename1,100);

imagejpeg($tmp2,$filename2,100);

 

// Delete tempfiles

imagedestroy($src);

imagedestroy($tmp);

imagedestroy($tmp1);

imagedestroy($tmp2);

=== SCRIPT ================================================================

 

 

Link to comment
Share on other sites

first, i assume that your measurements are in inches, not pixels. as 3.638 x 3.139 px doesn't make sense. (or are you using a . as thousands separator?)

 

anyway: the issue probably comes down to RAM. 2 images of the same pixel dimensions will not necessarily have the same file size. In fact, it would be very rare where 2 different images of the same pixel dimensions have the exact same file size. beyond pixel x pixel, there is the issue of color: how many colors and how much variation of colors from pixel to pixel. a 500 x 500 pixel image of a polar bear in a snowstorm would be far smaller than a 500 x 500 pixel image of the Mona Lisa.

 

in the end, the limit is probably the max memory allowed in php.ini and/or the max available on your server.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.