SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    GIF resize problems - black images and errors thrown

    I've got a script that uploads images, then re-sizes based on their file type. Everything was working fine (I assumed) until a GIF was uploaded. They are showing up as black images and the code is throwing an error:

    Warning: Wrong parameter count for imagecreatefromgif() in D:\xampp\htdocs\admin\functions\ImageResizer.php on line 17

    Warning: imagesx(): supplied argument is not a valid Image resource in D:\xampp\htdocs\admin\functions\ImageResizer.php on line 20

    Warning: imagesy(): supplied argument is not a valid Image resource in D:\xampp\htdocs\admin\functions\ImageResizer.php on line 21

    Warning: imagecopyresampled(): supplied argument is not a valid Image resource in D:\xampp\htdocs\admin\functions\ImageResizer.php on line 40

    Warning: imagedestroy(): supplied argument is not a valid Image resource in D:\xampp\htdocs\admin\functions\ImageResizer.php on line 54
    I have verified the image is uploaded correctly (comment out this code and checked the uploaded image, it is perfect) and I have verified the parameter (the image source) being given to imagecreatefromgif() is correct (D:/xampp/htdocs/artist_images/8/1247764323.gif is in fact the correct path to the image)

    the images are also ending up solid black. Here's some code, I am as stumped as I can be here ... been searching the internet for hours trying to find an answer.

    Code PHP:
    <?php
     
    class ImageResizer	 {
     
    	function resize_image($name, $path, $max)	{
     
    		$system = explode(".", $name);
     
    		if (preg_match("/jpg|jpeg/", strtolower($system[1])))	{
    			$src_img = imagecreatefromjpeg($path . "/" . $name);
    			}
    		else if (preg_match("/png/", strtolower($system[1])))	{
    			$src_img = imagecreatefrompng($path . "/" . $name);
    			}
    		else if (preg_match("/gif|giff/", strtolower($system[1])))	{
    			echo 'in giff params are' . $path , "/" . $name;
    			$src_img = imagecreatefromgif($path , "/" . $name);
    			}	
     
    		$old_x = imageSX($src_img);
    		$old_y = imageSY($src_img);
     
    		if ($old_x > $old_y) {
    			$thumb_w = $max;
    			$thumb_h = $old_y * ($max / $old_x);
    			}
     
    		if ($old_x < $old_y) {
    			$thumb_w = $old_x * ($max / $old_y);
    			$thumb_h = $max;
    			}
     
    		if ($old_x == $old_y) 	{
    			$thumb_w = $max;
    			$thumb_h = $max;
    			}
     
    		$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
     
    		imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); 
     
    		unlink($path . "/" . $name);
     
    		if (preg_match("/png/", strtolower($system[1])))	{
    			imagepng($dst_img, $path . "/" . $name); 
    			} 
    		else if (preg_match("/gif|giff/", strtolower($system[1])))	{
    			imagegif($dst_img, $path . "/" . $name); 
    			}
    		else {
    			imagejpeg($dst_img, $path . "/" . $name); 
    			}
    		imagedestroy($dst_img); 
    		imagedestroy($src_img); 
    		}
    	}
     
    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think maybe $src_img = imagecreatefromgif($path , "/" . $name); should be:

    $src_img = imagecreatefromgif($path . "/" . $name);

    imagecreatefromgif takes only one parameter.

  3. #3
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JDevereux View Post
    I think maybe $src_img = imagecreatefromgif($path , "/" . $name); should be:

    $src_img = imagecreatefromgif($path . "/" . $name);

    imagecreatefromgif takes only one parameter.
    OH GOD, here I was staring at that thing for hours and never noticed I mistakenly used a comma instead of a period .... MAN OH MAN

    thanks for the other set of eyes!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •