473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Getting and using binary image data from ImageMagick

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
2 4091
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: projecktzero | last post by:
Well, I've managed to get an image into a postgre database, but now I'm having trouble getting it out. #! /usr/bin/env python from pyPgSQL import PgSQL def main(): connectdb =...
2
by: Chucker | last post by:
Hi Community, I think I can store Binary Data in SQL Server but when I try to retrieve it, I always only get one byte. I think I stored my Binary Data in SQL Server in a Colum of Type Image....
4
by: Callum Prentice | last post by:
i need a "script" that i can use locally as well as online that will: * create a large (maybe something like 2k x 2k) master image in memory * open a text file and read all the lines from it...
5
by: firewoodtim | last post by:
I want to analyze a GIF file and retrieve the histogram data on the image (pixel quantity and color symbol for each color in the file.) Does anyone know how to use PHP to do this? I've looked...
2
by: ray_cam2006 | last post by:
I want to write a programe in graphic mode. As you know in C they allow us to use their font but I want to use Cambodian font, how can I do that ? I waiting for reply ! I hope that all of you help...
11
by: eholz1 | last post by:
Hello PHP group, I am using some php code to check the size of images, and then resize or determine new dimension for the image. GD seems quite slow. It takes about 5 seconds (plus or minus) to...
3
by: femtox77 | last post by:
Hi to all!!! I'm trying to convert a pdf file into an image, for example JPG or PNG format, with ImageMagick. I use the command line. For example: convert header.pdf header.jpg. But I obtain a...
6
by: William Gill | last post by:
I have found a couple of sites that allow a visitor to upload an image and the site returns either the "average color", or a palette of colors. Several of them use PHP to accomplish this. I have...
2
by: cssExp | last post by:
Is there a any way to watermark with another image (like a 24bit transparent png), and able to set opacity, preserve quality etc using imageMagick(not with magickWand). simply put how can i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.