transforming animated images into normal images
Posted: 2009-11-28T14:44:27-07:00
hello guys I hope someone can help me out with this I'm working with php and commanlines tools for imagemagick. I'm having a hard time to convert animated files to normal (just one frame image) when I do it by hand it works I can convert it easily using:
convert image.gif[0] image1.gif
but it won't work if I do this
convert image.gif[0] image.gif
this made me block gif upload for my users, but now some users found a glitched which they can hide a gif image by changing .gif to .jpeg and it would upload to the server without noticing it.
this is the code I have in my php website
any suggestion, comments, fixes to this problem would be greatly appreciated, my website is being flooded with this type of images and my bandwidth is going to the roof.
thanks.
convert image.gif[0] image1.gif
but it won't work if I do this
convert image.gif[0] image.gif
this made me block gif upload for my users, but now some users found a glitched which they can hide a gif image by changing .gif to .jpeg and it would upload to the server without noticing it.
this is the code I have in my php website
Code: Select all
$image_name = $userName."_".$t.".".$extension;
$image_name = str_replace (" ", "", $image_name); //I delete any blank space because it seems imagemagick doesn't like that and wont create thumbnail
$image_name_thumb = $userName."_".$t."_thumb.".$extension;
$image_name_thumb = str_replace (" ", "", $image_name_thumb);
//the new name will be containing the full path of the image where it will be stored (images folder)
$new_name = "user/".$image_name;
//we verify if the image has been uploaded, if it didn't php will show me an error
$copied = copy($_FILES['image']['tmp_name'], $new_name);
//creating the pic and also thumbnail
exec("convert user/$image_name -resize 500x800\> -quality 80 -compress JPEG user/$image_name"); //<---- this is where the image gets converted it, but when I put [0] in front of $image_name it doesn't respond at all
//creating thumbnail
if(!$imgsize = getimagesize($new_name)){//if we cant get size show there was an error
$success .= "<div id=\"fmsg\"><strong>Your picture contains errors.</div>";
}else{
if ($imgsize[0] > $imgsize[1] ) {
$imgsize = "x100";
} else {
$imgsize = "100x";
}
$cmd = "-size 300x300 user/$image_name -resize $imgsize -gravity center -crop 100x75+0+0 +repage";
exec("convert $cmd user/$user_folder/$image_name_thumb");
}
thanks.