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;
}