can't php upload images direct from camera?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
quakeglen
Forum Newbie
Posts: 1
Joined: Tue Dec 01, 2009 2:53 pm

can't php upload images direct from camera?

Post by quakeglen »

Hi there,

i'm just building a website where users can upload their own images to website.

I have a problem when i select an image just copied from camera... but if i open this image in photoshop and save it, there is no problem.

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in

i'm using this function to upload images:

Code: Select all

 
function getImg($ffoto, $width, $height, $quality, $target1){
 
$size = getimagesize($ffoto);
// scale evenly
$ratio = $size[0] / $size[1];
if ($ratio >= 1){
     $scale = $width / $size[0];
} else {
     $scale = $height / $size[1];
}
// make sure its not smaller to begin with!
if ($width >= $size[0] && $height >= $size[1]){
     $scale = 1;
}
 
$archivo = basename($target1);
$extension = explode('.',$archivo);
$ext = $extension[1];
 
if($ext == 'jpg' || $ext == 'jepg'){
    $im_in = imagecreatefromjpeg ($ffoto);
}
 
if($ext == 'png'){
    $im_in = imagecreatefrompng ($ffoto);
}
 
if($ext == 'bmp'){
    $im_in = imagecreatefrombmp ($ffoto);
}
 
if($ext == 'gif'){
    $im_in = imagecreatefromgif ($ffoto);
}
 
 
$im_out = imagecreatetruecolor($size[0] * $scale, $size[1] * $scale);
imagecopyresampled($im_out, $im_in, 0, 0, 0, 0, $size[0] * $scale, $size[1] * $scale, $size[0], $size[1]); //here's the error
 
if ($ext == 'png' || $ext == 'bmp' || $ext == 'gif'){
    $target1 = substr($target1,0,-3);
    $target1 = $target1 . 'jpg';
}
 
imagejpeg($im_out, $target1, $quality);
 
imagedestroy($im_out);
imagedestroy($im_in);
 
return $exts;
}
 
why camera's images have problems and other type don't? thanks
Post Reply