473,698 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ex e -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 (ÿØÿÃ*�JF IF�,,� �ÿÛ�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 4102
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.ex e -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.ex e -size 250x250 \"$photo\"" .
' -resize 125x125' .
' -strip' .
' -unsharp 0.2x0.6+1.0' .
' -quality 87 JPG:-';

header("Conten t-type: image/jpeg");
passthru($cm d, $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
2408
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 = PgSQL.connect('server:port:database:username:password') cur = connectdb.cursor()
2
3750
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. At least when I execute the following code, I get some significant network traffic. When I check the database with query analyzer, I see 4 Hex Chars in the image colum. Like 0xe0 etc.
4
9577
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 (maybe 1000 lines max) * each line is composed of an x, y, name and a png image filename * for each line, open the png image and position it in the master image at the location given by x & y * save off the master image to a png at the end
5
2664
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 through the PHP documentation, the GD image library, and the ImageMagick command-line imaging system and found very little that I could use. The best thing I've found so far is an "identify -verbose" command from ImageMagick that gives the data I...
2
1580
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 me to solve this problem! Thank in Advance
11
2351
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 calulate dimension for 7 jpeg images. I have a 700mhz processor (Pentium III, remember those??)! with almost a gb of memory. Is that the way GD is??? Here is a snippet of the dode I use: I pass
3
8560
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 bad result. The jpg's quality is very low. Why? I tried to use - quality 100 option but there isn't improvement. I think also that this option isn't active for the pdf conversion to an image format or not? I need some good ideas :D... Thanks to...
6
1910
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 requested the source code, but have not gotten a response (even though one site states "source code available on request"). It is obvious that they read the colors of each pixel and them manipulate that data. I would like to be able to do...
2
3592
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 watermark a image with another with imageMagick i want to be able to set -gravity and also set opacity. Please help.
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.