Jump to content

move_uploaded_file, imagecreatefromjpeg max limit, but it's already on server?


Recommended Posts

Could one of you kind folks have a look at this and give me some insight as to why, when the uploaded image is say greater than 3.5 mb, the lowRes image does not get created?

 

A temp dir is created, the uploaded file gets moved there (no matter it's size), the doResize function gets called pointing back to the temp dir and file to create the thumbnail, this works (no matter it's size). Now the problem, when the doResize is called to create the lowRes image, if the file is below 3.5mb, it works, but when it's above, it does not.

 

The obvious thing is there is a max limit of some sort, but here's the kicker, the file (no matter it's size) is has already been moved to the temp dir and resides on the server. Now if the function is just pointing to the file already residing on the server, why won't it create the lowRes?

 

Thanks in advance, any help would be greatly appreciated.

 

  $temp_file_dir  = "./temp_file/";
  $file_dir  = "../fscommand/media/images/images/"; 
  $resize_Image = 800;
  $imageQuality = 90;
  $thumb_dir ="../fscommand/media/images/thumbnails/";
  $resize_Thumbnail = 100;
  $thumbQuality = 75;
//create the directory if doesn't exists (should have write permissons)
if(!is_dir($temp_file_dir)) mkdir($temp_file_dir, 0666);
  ////////////
function doResize($srcDirectory, $targetDirectory, $targetSize, $targetQuality)
{
	$img = imagecreatefromjpeg($srcDirectory);
	$width = imagesx($img);
	$height = imagesy($img);
////////////////////////////////////////////
	if($width>$height){
     		$new_width = $targetSize;
      		$new_height = floor( $height * ( $targetSize / $width ) );

	}else if($height>$width){
     		$new_width = floor( $width * ( $targetSize / $height ) );
     		$new_height = $targetSize;

	}else if($height==$width){
     		$new_width = $targetSize;
     		$new_height = $targetSize;

	}
      // create a new temporary image
        $image_resized = imagecreatetruecolor( $new_width, $new_height );

      // copy and resize old image into new image
        imagecopyresampled( $image_resized, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

imagejpeg($image_resized, $targetDirectory, $targetQuality);
// free memory used
imagedestroy($image_resized);
imagedestroy($img);
}
//move the uploaded file
move_uploaded_file($_FILES['Filedata']['tmp_name'], $temp_file_dir.$_FILES['Filedata']['name']);
//
doResize($temp_file_dir.$_FILES['Filedata']['name'], $thumb_dir.$_FILES['Filedata']['name'], $resize_Thumbnail);
doResize($temp_file_dir.$_FILES['Filedata']['name'], $file_dir.$_FILES['Filedata']['name'], $resize_Image);

Thanks for the reply lightningstrike,

 

Just so I have this straight, the reason is because jpgs are compressed and when imagecreatefromjpeg() is run it needs a huge amount of memory to unpack the jpg and resample it, depending on the original size. Is there a way to dynamically check the amount of memory needed?

 

Thanks again.

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.