0

Hello I have added a simple image resize which is breaking my GIF animations. Could someone help me decipher here what needs to be removed from my existing code to allow that image to be uploaded and then be animated in GIF form...thank you for any input.

 case 'addgift':
            if($adminLevel == 4)
            {
                if ($_FILES['uploadedfile']['tmp_name'] != "")
                {
                    $image = new SimpleImage();
                    $image->load($_FILES['uploadedfile']['tmp_name']);
                    $width = $image->getWidth();
                    $height = $image->getHeight();
                    if($width > 64) {
                       $height = (64/$width)*$height;
                       $width = 64;
                    }
                    if($height > 64) {
                       $width = (64/$height)*$width;
                       $height = 64;
                    }
                    $image->resize($width,$height);
                    if(preg_match("/\.(png)$/i", $_FILES['uploadedfile']['name']))
                        $type = IMAGETYPE_PNG;
                    else if(preg_match("/\.(gif)$/i", $_FILES['uploadedfile']['name']))
                        $type = IMAGETYPE_GIF;
                    else
                        $type = IMAGETYPE_JPEG;
                    $image->save("images/gifts/".$_FILES['uploadedfile']['name'], $type);
                    unlink($_FILES['uploadedfile']['tmp_name']);

                    mysql_query("INSERT INTO gifts
                                (name, image, cash, tokens)
                                VALUES ('".mysql_real_escape_string($_POST['name'])."', '".$_FILES['uploadedfile']['name']."', ".intval($_POST['cash']).", ".intval($_POST['tokens']).")");
                    mysql_query("INSERT INTO admin_actions
                                (id1, id2, action, extra, time)
                                VALUES($userid, 0, '{id1} added gift \"{extra}\".', '".mysql_real_escape_string($_POST['name'])."', UNIX_TIMESTAMP())");
                }
            }
            break;

2 Answers2

0

Please check the following answer for details.

Resize animated GIF file without destroying animation

Always search before you post.

Community
  • 1
  • 1
intractve
  • 6,751
  • 1
  • 14
  • 12
0

I don't know if your lib supports such thing. What you can do is check that the image already meets the size limit and keep it untouched in case it does.

- $image->resize($width,$height);
- $image->save("images/gifts/".$_FILES['uploadedfile']['name'], $type);
- unlink($_FILES['uploadedfile']['tmp_name']);

+ if ($image->getWidth() == $width && $image->getHeight() == $height)
+     move_uploaded_file($_FILES['uploadedfile']['tmp_name'], "images/gifts/".$_FILES['uploadedfile']['name']);
+ else
+ {
+     $image->resize($width,$height);
+     $image->save("images/gifts/".$_FILES['uploadedfile']['name'], $type);
+     unlink($_FILES['uploadedfile']['tmp_name']);
+ }
Havenard
  • 27,022
  • 5
  • 36
  • 62
  • Thanks for your input its much appreciated. it appears from the various problems encountered I will be more productive just coding the entire file upload from scratch...thanks for your help – Jon Hopkins Aug 24 '14 at 14:00