Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with imagecreatefromgif()

Status
Not open for further replies.

spacebass5000

Programmer
Nov 26, 2000
144
0
0
US
My webserver uses:

PHP Version 4.4.2
Zend Optimizer v2.5.10

gd
GD Support enabled
GD Version bundled (2.0.28 compatible)
FreeType Support enabled
FreeType Linkage with freetype
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled

I am simply tring to use imagecreatefromgif() to create a gif. I keep getting the following error:

Warning: imagecreatefromgif(): '/home/omnipcs/public_html/devel/example/components/com_mtree/img/listings/34_test.gif' is not a valid GIF file in /home/omnipcs/public_html/devel/example/components/com_example/includes/example.image.functions.php on line 36

The file is indeed where it should be, it exists, and is a gif that I JUST created in photoshop. I cannot seem to get around this error and I have found nothing on the web to help me.

Can anyone here shed any light onto why I am getting this error? This is how the function is being called:

$logo = imagecreatefromgif($image);

Image points to: /home/omnipcs/public_html/devel/example/components/com_mtree/img/listings/34_test.gif

Which like I said, exists and is in fact a gif.
 
You said:
Image points to: /home/omnipcs/public_html/devel/example/components/com_mtree/img/listings/34_test.gif

Your use of "points to" has piqued my interest. Does the variable $image contain a file handle to the file or the string of the filename? The function requires the latter.



Want the best answers? Ask the best questions! TANSTAAFL!
 
and the funny thing is, I have utilized this code to provide jpg support:

Code:
$ext = strtolower(substr($link->link_image, -3, 3));
		
		echo "<p>ext = $ext</p>";

		switch($ext)
		{
			case "gif":
				$logo = imagecreatefromgif($image);
				$coupon_base = $mosConfig_absolute_path."/components/com_dineus/images/coupon.gif";
				$coupon_template = imagecreatefromgif( $coupon_base );
				break;
			
			case "jpg":
				$logo = imagecreatefromjpeg($image);
				$coupon_base = $mosConfig_absolute_path."/components/com_dineus/images/coupon.jpg";
				$coupon_template = imagecreatefromjpeg( $coupon_base );
				break;
			
			/*case "png":
				$logo = imagecreatefrompng($image);
				break;*/
				
			default:
				echo "<script language=\"Javascript\"> alert('Error: Not a valid image file.') </script>";
				return '';	
		}

I do not get any errors when trying this with a jpg yet it doesn't work My finished result does not contain the original image.
 
GIFs have long been problematic in PHP.

Parts of the GIF spec were patented until recently, and there are so many variants.

On the thought of variants...Have you tried another GIF? One that you download from somewhere?



Want the best answers? Ask the best questions! TANSTAAFL!
 
ok, looking at the gd home page and then following it to
i came across using getImageSize to print out the images pertinent info. I am getting this:

Code:
Array ( [0] => 220 [1] => 136 [2] => 2 [3] => width="220" height="136" [bits] => 8 [channels] => 3 [mime] => image/jpeg )

for a gif. Note the mime setting. Why on earth would this happen? Could it be an improper server config?
 
ok, here is the weirdness....

obviously the mime-type of my gif is being altered upon upload and storage on the server. when I manually upload and run this code, all is well. when I upload from my browser, it breaks.

Anyone have any insight?
 
the filename is derived from the $_FILES variable and the file gets put in place by rename() or move_uploaded_file().
 
Drat. That's all the easy stuff, I think.

When you upload the graphic through your script, does the file have the right number of bytes?



Want the best answers? Ask the best questions! TANSTAAFL!
 
I figured it out. The 3pd application I was using makes painstaking efforts to check the input files yet regardless if they are gif, jpg, or png ends up writing them as jpg's.


Code:
switch($imginfo[2]) {
						case 'JPG':
							$src_img = imagecreatefromjpeg($this->tmpFile);
							break;

						case 'PNG':
							$src_img = imagecreatefrompng($this->tmpFile);
							break;
						
						case 'GIF':
							$src_img = imagecreatefromgif($this->tmpFile);
							break;
					}

					if (!$src_img){
						$ERROR = $lang_errors['invalid_image'];
						return false;
					}
					$dst_img = imagecreatetruecolor($destWidth, $destHeight);
					imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int)$destHeight, $srcWidth, $srcHeight);
					
					imagejpeg($dst_img, $this->directory.$this->imageName, $this->quality);

awesome... good stuff, yay even

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top