A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearHow can I upload/resize images taken with a digital camera? - page 1
User InfoPosts
How can I upload/resize images taken with a digital camera?#1
I am working on a building a gallery and the goal is a low barrier of entry. My user is someone who takes pictures using their digital camera so file size would be between 200 - 400 KB per image.

The problem I am running into using the GD library is that each image when resized and uploaded use about 90MB of memory+ when the server has a 64 MB limit.

When I use ImageMagick it times out and throws an internal server error.

I am wondering if anyone has any experience with uploading/resizing such large image sizes and could give me some pointers.

Thanks,
Levi

edit: Here is my code to upload

	 /** Begin Multiple Image Upload**/     
$numberImages = count($_FILES[(galFile(][(name(])-1;

for($i=1;$i<=$numberImages;$i++)
{
$imageName = $_FILES[(galFile(][(name(][$i];
$imageType = $_FILES[(galFile(][(type(][$i];
$imageSize = $_FILES[(galFile(][(size(][$i];
$imageTemp = $_FILES[(galFile(][(tmp_name(][$i];
$imageError = $_FILES[(galFile(][(error(][$i];

//Make sure it is an image
if(in_array(end(explode(".", $imageName)), $allowed))
{
//Where to upload image to
$uploadFile = $uploadDir . $imageName;
if (file_exists($uploadFile))
{
//What to do if file already exists
//Append random number to the end
$front = explode(".", $imageName);
$randomNum = rand(1,100);
$front[0] = $front[0].$randomNum;
$imageName = $front[0].".".$front[1];
$uploadFile = $uploadDir . $imageName;
}
if(move_uploaded_file($imageTemp,$uploadFile))
{
//Add $imageName to DB
$query = "INSERT INTO galleryImages VALUES(\"0\",\"$lastInsert\",\"$imageName\",\"$i\")";
mysql_query($query);
reSizePic($uploadFile);
}
}
}


Here is the GD code I had been using to resize:

function reSizePic($image)
{
$source_pic = $image;
$destination_pic = $image;
$max_width = 660;
$max_height = 500;

$src = imagecreatefromjpeg($source_pic);
list($width,$height)=getimagesize($source_pic);

$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;

if(($width <= $max_width) && ($height <= $max_height))
{
$tn_width = $width;
$tn_height = $height;
}
elseif (($x_ratio * $height) < $max_height)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else
{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}

$tmp = imagecreatetruecolor($tn_width,$tn_height);

imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);

imagejpeg($tmp,$destination_pic,100);
imagedestroy($src);
imagedestroy($tmp);
}


And this is the ImageMagick code I am using to resize:

$resource = NewMagickWand(); 
MagickReadImage($resource,$image);
MagickSetImageCompressionQuality( $resource, 100);
$resource = MagickTransformImage($resource,(0x0(,(660x500();
MagickWriteImage($resource, $image);
DestroyMagickWand($resource);

posted date: 2009-04-16 20:30:00


Re: How can I upload/resize images taken with a digital camera?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-16 20:30:01


Re: How can I upload/resize images taken with a digital camera?#3
You're probably doing something inefficiently because ImageMagick should be able to handle 400kb images with no problem. How many are you trying to resize at once? Can you post your code?

posted date: 2009-04-16 20:32:00


Re: How can I upload/resize images taken with a digital camera?#4
I assume you're opening a file but not closing it or something to get that much memory usage. Post your code maybe?

posted date: 2009-04-16 20:34:00


Re: How can I upload/resize images taken with a digital camera?#5
I wouldn't rely on 200-400KB too much - 3.2 to 5megapixel cellphone cameras are common these days.

posted date: 2009-04-16 20:43:00


Re: How can I upload/resize images taken with a digital camera?#6
I added in my code above.

posted date: 2009-04-16 20:46:00


Re: How can I upload/resize images taken with a digital camera?#7
http://pl.php.net/imagecreatefromjpegThe memory required to load an image using imagecreatefromjpeg() is a function of the image(s dimensions and the images(s bit depth, multipled by an overhead. It can calculated from this formula: Num bytes = Width * Height * Bytes per pixel * Overhead fudge factor Where Bytes per pixel = Bit depth/8, or Bits per channel * Num channels / 8.That(s about the GD part. Now the ImageMagick: have you tried a simpler approach:$thumb = new Imagick((image.jpg();$thumb->resizeImage($w,$h,Imagick::FILTER_LANCZOS,1);$thumb->writeImage((thumb.jpg();$thumb->destroy();

posted date: 2009-04-16 21:39:00


Re: How can I upload/resize images taken with a digital camera?#8
"with 1.5 GBs RAM. Nothing special." vs "the server has a 64 MB limit.". run a 64mb ini_set an try. check my answer for calculations.

posted date: 2009-04-16 22:27:00


Re: How can I upload/resize images taken with a digital camera?#9
I dont know anything about this question, but is the following answer usefulhttp://www.momige.com/74315/what-is-the-best-way-to-handle-photo-uploadsJust in case it is not, ignore it.

posted date: 2009-04-16 22:56:00


Re: How can I upload/resize images taken with a digital camera?#10
The above for ImageMagick did not work. It says, "Fatal error: Class 'Imagick' not found" I am using Hostgator and they have Magickwand installed, do you know if this means I can only use Magickwand commands?

posted date: 2009-04-17 10:12:00


Re: How can I upload/resize images taken with a digital camera?#11
Took this example from the docs comments, if you have the magick package installed, It shoud work, I think.

posted date: 2009-04-17 10:52:00


Re: How can I upload/resize images taken with a digital camera?#12
The code I have resizes the images fine for the first 15 images uploaded. If I upload more than 15 it doesn't end so I believe it is something to do with the server and some sort of a timeout.

posted date: 2009-04-20 18:45:00


select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.