By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,587 Members | 1,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,587 IT Pros & Developers. It's quick & easy.

Getting and using binary image data from ImageMagick

P: n/a
I am trying to use ImageMagick to create thumbnails on the fly - without
having to save the image to a file.

I have gotten it to work by using passthru($cmd, $retval), but I want to
use something else that will give me the complete output returned as a
string that I can convert to a GD lib image resource so I can verify the
operation worked before sending the Content-type header for the image.

This works:
---------------------------------------------------------
// $photo = path to image file
$cmd = "convert.exe -size 250x250 \"$photo\"" .
' -resize 125x125' .
' -strip' .
' -unsharp 0.2x0.6+1.0' .
' -quality 87 JPG:-';

header("Content-type: image/jpeg");
passthru($cmd, $retval);
---------------------------------------------------------

Using this, the resized image is displayed in my browser.

However, I would rather get the binary output from ImageMagick into a
variable and then test retval (or use some other method) to determine if
the operation was successful.

I've tried shell_exec ...
$output = shell_exec($cmd);
.... but the data in $output appears truncated (ÿØÿ*�JFIF�,,��ÿÛ�C�
- is all there is). ??

Has anyone done anything like this? Any suggestions?

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************
Jul 19 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You can use this code, but change the command:

http://groups.google.com/group/comp....cf2cff276c5003

That will only print the header if the command starts generating good
output.

By the way, for a generic resize script with more options and file
caching, use:

http://phpthumb.sourceforge.net/

On Jul 19, 1:30 am, Chuck Anderson <websiteaddr...@seemy.sigwrote:
I am trying to use ImageMagick to create thumbnails on the fly - without
having to save the image to a file.

I have gotten it to work by using passthru($cmd, $retval), but I want to
use something else that will give me the complete output returned as a
string that I can convert to a GD lib image resource so I can verify the
operation worked before sending the Content-type header for the image.

This works:
---------------------------------------------------------
// $photo = path to image file
$cmd = "convert.exe -size 250x250 \"$photo\"" .
' -resize 125x125' .
' -strip' .
' -unsharp 0.2x0.6+1.0' .
' -quality 87 JPG:-';

header("Content-type: image/jpeg");
passthru($cmd, $retval);
---------------------------------------------------------

Using this, the resized image is displayed in my browser.

However, I would rather get the binary output from ImageMagick into a
variable and then test retval (or use some other method) to determine if
the operation was successful.

I've tried shell_exec ...
$output = shell_exec($cmd);
... but the data in $output appears truncated (?JFIF?,,???C?
- is all there is). ??

Has anyone done anything like this? Any suggestions?

--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
*****************************

Jul 19 '07 #2

P: n/a
petersprc wrote:
You can use this code, but change the command:

http://groups.google.com/group/comp....cf2cff276c5003

That will only print the header if the command starts generating good
output.
Thanks. (I take it that's yours.) It'll take me a little while to wrap
my head around that, but I will.
By the way, for a generic resize script with more options and file
caching, use:

http://phpthumb.sourceforge.net/
Some things I like doing myself, but that sure is a robust,
all-encompassing thumbnail generator. I think it does, too much.

Thanks,
Chuck
On Jul 19, 1:30 am, Chuck Anderson <websiteaddr...@seemy.sigwrote:
>I am trying to use ImageMagick to create thumbnails on the fly - without
having to save the image to a file.

I have gotten it to work by using passthru($cmd, $retval), but I want to
use something else that will give me the complete output returned as a
string that I can convert to a GD lib image resource so I can verify the
operation worked before sending the Content-type header for the image.

This works:
---------------------------------------------------------
// $photo = path to image file
$cmd = "convert.exe -size 250x250 \"$photo\"" .
' -resize 125x125' .
' -strip' .
' -unsharp 0.2x0.6+1.0' .
' -quality 87 JPG:-';

header("Content-type: image/jpeg");
passthru($cmd, $retval);
---------------------------------------------------------

Using this, the resized image is displayed in my browser.

However, I would rather get the binary output from ImageMagick into a
variable and then test retval (or use some other method) to determine if
the operation was successful.

I've tried shell_exec ...
$output = shell_exec($cmd);
... but the data in $output appears truncated (?JFIF?,,???C?
- is all there is). ??

Has anyone done anything like this? Any suggestions?

--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
*****************************



--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
Everyone's journey should be different,
so that we all are enriched
in new and endless ways
*****************************
Jul 20 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.