views:

20

answers:

1

Hi all,

I'm trying to do a simple thumbnail generation from an image that isn't located on my server using the iMagick wrapper for ImageMagick. For some reason, the following code will not display anything when called:

<?php
   $image = new Imagick("http://kunaki.com/ProductImage.ASP?T=I&amp;ST=FO&amp;PID=PX003Y9EDJ");
   $image->thumbnailImage(100, 0);
   header( "Content-Type: image/jpg" );
   echo $image;
?>

I've also tried using http://kunaki.com/ProductImage.ASP?T=I&amp;ST=FO&amp;PID=PX003Y9EDJ.jpg to no avail.

Based on comments below, I've attempted this as well with no results, but am not sure if the syntax is correct.

<?php
   $kunaki_image = file_get_contents("http://kunaki.com/ProductImage.ASP?T=I&amp;ST=FO&amp;PID=PX003Y9EDJ");
   $name = tempnam("/tmp", "kunaki");
   $final = file_put_contents($name, $kunaki_image);
   $image = new Imagick($final);
   $image->thumbnailImage(100, 0);
   header( "Content-Type: image/jpg" );
   echo $image;
?>

Does anyone have any suggestions?

Thanks!

+1  A: 

ImageMagick's constructor is badly documented so I can't tell for sure, but maybe Imagick can't deal with remote file paths.

Try fetching it separately e.g. using file_get_contents() or curl. Store it locally under a temporary name, and pass it that.

Pekka
I tried with local image it is not any good either!
Trufa
@Trufa meaning what exactly? What happens?
Pekka
I get this error: Parse error: syntax error, unexpected T_STRING in /home/jmvarela/public_html/ihateyourjacket.com/game/image.php on line 2 with either one...
Trufa
@Trufa that error has nothing to do with whether the file is fetched remotely or locally. It is a sign of a syntax error on line 2.
Pekka
i tried `file_get_contents()` , nothing. How would I approach storing locally, then removing when the page is closed?
Dave Kiss
@Dave get data using `file_get_contents()`, create temporary file name using `tempnam()`, save to file using `file_put_contents()`
Pekka
Updated my question, can you check it out?
Dave Kiss
@Dave turn error reporting on: `error_reporting(E_ALL);`, it will show you what goes wrong
Pekka
Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `/home/davekiss/public_html/ÿØÿà': No such file or directory @ blob.c/OpenBlob/2403' in /home/davekiss/public_html/thumbnail-generator.php:4 Stack trace: #0 /home/davekiss/public_html/thumbnail-generator.php(4): Imagick->__construct('??????JFIF?????...') #1 {main} thrown in /home/davekiss/public_html/thumbnail-generator.php on line 4
Dave Kiss
@Dave you need to do `$image = new Imagick($name);`
Pekka
that worked! how does `file_put_contents()` play into the `$name` variable that is passed into the IMagick class?
Dave Kiss
@Dave play how?
Pekka
nevermind, I see what is happening now. Thanks a bunch! Wish I didn't have to store locally, but this will do.
Dave Kiss