Connecting Tech Pros Worldwide Help | Site Map

Workaround for "imagegif()"?

Phil Powell
Guest
 
Posts: n/a
#1: Jul 17 '05
re: http://us4.php.net/manual/en/function.imagegif.php

I have one class method that resizes images, including GIF images, and
works just fine doing so, even up to this line:

[PHP]
eval('image' . $extArray[$type] . '($newImage, "$tmpImageDownloadDir/"
.. $this->fileName);'); // SAVE TO TEMPORARY IMAGE DIR FOR
DOWNLOAD
[/PHP]

(yes even with.. EVAL!)

However, in another class method, THIS line produces the following
error:

Quote:
Fatal error: Call to undefined function: imagegif() in
/www/html/mu-spin/image_catalog/include/classes.inc.php(2262) :
eval()'d code on line 1
The line:

[PHP]
eval('image' . $extArray[$type] . '($newImage,
"$this->thumbLocationPath/$this->fileName", $thumbDimensionInt);');
[/PHP]

I've taken out the reference to $thumbDimensionInt, to no avail. Same
exact error every time, but ONLY for GIF images.

But why is it the nearly-identical line in one class method resizes
GIF images, but the near very same line in another class method
(creates thumbnails) bombs for GIF images?

Both work just fine for all other images (i.e., JPG, TIFF, PNG, SWF,
BMP, etc.)

Thanx
Phil
Andy Hassall
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Workaround for "imagegif()"?


On 7 May 2004 15:21:39 -0700, soazine@erols.com (Phil Powell) wrote:
[color=blue]
>re: http://us4.php.net/manual/en/function.imagegif.php
>
>I have one class method that resizes images, including GIF images, and
>works just fine doing so, even up to this line:
>
>[PHP]
>eval('image' . $extArray[$type] . '($newImage, "$tmpImageDownloadDir/"
>. $this->fileName);'); // SAVE TO TEMPORARY IMAGE DIR FOR
>DOWNLOAD
>[/PHP]
>
>(yes even with.. EVAL!)
>
>However, in another class method, THIS line produces the following
>error:
>
>
Quote:
>Fatal error: Call to undefined function: imagegif() in
>/www/html/mu-spin/image_catalog/include/classes.inc.php(2262) :
>eval()'d code on line 1
>
>
>The line:
>
>[PHP]
>eval('image' . $extArray[$type] . '($newImage,
>"$this->thumbLocationPath/$this->fileName", $thumbDimensionInt);');
>[/PHP]
>
>I've taken out the reference to $thumbDimensionInt, to no avail. Same
>exact error every time, but ONLY for GIF images.
>
>But why is it the nearly-identical line in one class method resizes
>GIF images, but the near very same line in another class method
>(creates thumbnails) bombs for GIF images?
>
>Both work just fine for all other images (i.e., JPG, TIFF, PNG, SWF,
>BMP, etc.)[/color]

Hm - you're _sure_ that the first one is actually calling imagegif? Unless
you're running a very old version of GD it shouldn't work, should give the
error you've posted. GIF support was removed ages ago because of the patent
restrictions surrounding the format (although read-only GIF support was patched
back in the version of GD bundled with recent PHPs).

Incidentally, wouldn't call_user_func be safer than eval? e.g.

<?php
$x = imagecreatefromgif('circle_1.gif');
$type = 'png';
header("Content-type: image/$type");
call_user_func("image$type", $x);
?>

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Chung Leong
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Workaround for "imagegif()"?


"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:eo5o90t5ig388t9h2t7cdhbu35lq7jniif@4ax.com...[color=blue]
> On 7 May 2004 15:21:39 -0700, soazine@erols.com (Phil Powell) wrote:
> Hm - you're _sure_ that the first one is actually calling imagegif?[/color]
Unless[color=blue]
> you're running a very old version of GD it shouldn't work, should give the
> error you've posted. GIF support was removed ages ago because of the[/color]
patent[color=blue]
> restrictions surrounding the format (although read-only GIF support was[/color]
patched[color=blue]
> back in the version of GD bundled with recent PHPs).[/color]

The LZW patent expired last year. I wonder why they haven't yet restored GIF
support.
[color=blue]
> Incidentally, wouldn't call_user_func be safer than eval? e.g.
>
> <?php
> $x = imagecreatefromgif('circle_1.gif');
> $type = 'png';
> header("Content-type: image/$type");
> call_user_func("image$type", $x);
> ?>[/color]

Personally I like to do this:

$imagecreatefrom_func = array(
1 => "imagecreatefromgif",
3 => "imagecreatefrompng",
2 => "imagecreatefromjpeg");

$image_func = array(
1 => "imagepng",
3 => "imagepng",
2 => "imagejpeg");

list($width, $height, $type, $attr) = getimagesize($filename);

if($f = @$imagecreatefrom_func[$type]) {
$g = $image_func[$type];
$img = $f($filename);
// do stuff with image
$g($img);
}

An elegant and flexible setup, methinks.


Andy Hassall
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Workaround for "imagegif()"?


On Mon, 10 May 2004 19:44:41 -0400, "Chung Leong" <chernyshevsky@hotmail.com>
wrote:
[color=blue]
>The LZW patent expired last year. I wonder why they haven't yet restored GIF
>support.[/color]

It hasn't expired all round the world yet. That happens on July 7th 2004.

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Phil Powell
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Workaround for "imagegif()"?


"Chung Leong" <chernyshevsky@hotmail.com> wrote in message news:<T4udnXZMr7Tlij3dRVn-gg@comcast.com>...[color=blue]
> "Andy Hassall" <andy@andyh.co.uk> wrote in message
> news:eo5o90t5ig388t9h2t7cdhbu35lq7jniif@4ax.com...[color=green]
> > On 7 May 2004 15:21:39 -0700, soazine@erols.com (Phil Powell) wrote:
> > Hm - you're _sure_ that the first one is actually calling imagegif?[/color]
> Unless[color=green]
> > you're running a very old version of GD it shouldn't work, should give the
> > error you've posted. GIF support was removed ages ago because of the[/color]
> patent[color=green]
> > restrictions surrounding the format (although read-only GIF support was[/color]
> patched[color=green]
> > back in the version of GD bundled with recent PHPs).[/color]
>
> The LZW patent expired last year. I wonder why they haven't yet restored GIF
> support.
>[color=green]
> > Incidentally, wouldn't call_user_func be safer than eval? e.g.
> >
> > <?php
> > $x = imagecreatefromgif('circle_1.gif');
> > $type = 'png';
> > header("Content-type: image/$type");
> > call_user_func("image$type", $x);
> > ?>[/color]
>
> Personally I like to do this:
>
> $imagecreatefrom_func = array(
> 1 => "imagecreatefromgif",
> 3 => "imagecreatefrompng",
> 2 => "imagecreatefromjpeg");
>
> $image_func = array(
> 1 => "imagepng",
> 3 => "imagepng",
> 2 => "imagejpeg");
>
> list($width, $height, $type, $attr) = getimagesize($filename);
>
> if($f = @$imagecreatefrom_func[$type]) {
> $g = $image_func[$type];
> $img = $f($filename);
> // do stuff with image
> $g($img);
> }
>
> An elegant and flexible setup, methinks.[/color]


That's to an extent what I'm doing, however, "$g($img)" I was unaware
would work standalone. Because of the code structure I might fare
better with call_user_func, will give that a whirl.

Phil
Closed Thread