resizing an image without saving it

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
lola

resizing an image without saving it

Post by lola »

I'm trying to figure out if IM can do what I need it to do.
What I have is an enewsletter, with one image per issue.
The newsletter is built using an html form saving to a sql server, prepared with php, and presented in html.
The image we use is a link to a jpg - the image is never saved anywhere locally. It needs to be roughly 150x150, which means a stupid amount of googling is required to find something appropriate. What I want to be able to do is to pick any image in any size, and use that link for the image, and then at some point resize it so when the html newsletter is created it appears as 150x150ish.
Is this even theoretically possible, or does the image need to be saved somewhere in order to manipulate it with IM?
Thank you!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: resizing an image without saving it

Post by Bonzo »

Try this:

Code: Select all

<?php
$photo="http://www.website.com/input_image.jpg";
$cmd = "convert $photo -thumbnail 150x150! JPG:-";

header("Content-type: image/jpeg");
passthru($cmd, $retval);
?>
Save this as a php page called something like image.php; then use <img src="image.php"> where you want it displayed.
lola

Re: resizing an image without saving it

Post by lola »

Thanks!

That certainly looks like it should work... But I'm still having trouble (it's just showing a broken img link). There are probably 2 reasons for any problems I might be having:

1) I don't really know php. But that shouldn't have an impact, since your instructions were very clear and simple, and I know that the page I started with worked fine before.
2) I'm not 100% that ImageMagick installed properly. It seemed to, and it looks like everything is there and the Displayer works fine, but when I did the test suggested on the download page (i.e., convert logo: logo.gif ; identify logo.gif ; display logo.gif) the display step didn't work. At first I was geting an error saying something like image not found, but when I did it just now it says "display.exe: unable to open X server. `'[No such file or directory.]"
Should I just try reinstalling?

Thank you!!

Bonzo wrote:Try this:

Code: Select all

<?php
$photo="http://www.website.com/input_image.jpg";
$cmd = "convert $photo -thumbnail 150x150! JPG:-";

header("Content-type: image/jpeg");
passthru($cmd, $retval);
?>
Save this as a php page called something like image.php; then use <img src="image.php"> where you want it displayed.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: resizing an image without saving it

Post by Bonzo »

Try some of the code here to find your version etc. http://www.rubblewebs.co.uk/imagemagick ... server.php

You probably do not have an X server that is why you are getting that error and you do not need it for what you want.

To get the image from another website I think you need wget installed; I do not know at the moment how to check it is installed.

You did change this to a valid image somewhere ?
http://www.website.com/input_image.jpg e.g. http://www.rubblewebs.co.uk/imagemagick ... flower.jpg

Note:
The resize I put 150x150! resizes exactly to 150x150, to keep the aspect ratio use 150x150
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: resizing an image without saving it

Post by Bonzo »

I have been assuming you are on a unix server and if so try this to check you have wget installed:

Code: Select all

<?php
echo "<pre>";
system("which wget");  
system("wget --version");
echo "</pre>";
?> 
Slig

Re: resizing an image without saving it

Post by Slig »

I think that you're better off caching the small image somewhere, otherwise i'll be calling IM every single time that the newsletter is showed.
lola

Re: resizing an image without saving it

Post by lola »

Slig wrote:I think that you're better off caching the small image somewhere, otherwise i'll be calling IM every single time that the newsletter is showed.
hm, good point. I'm not sure that's a problem though - the newsletter is first sent as an html attachment, which is how most people view it - the actual webpage isn't used too much.
lola

Re: resizing an image without saving it

Post by lola »

Bonzo wrote:Try some of the code here to find your version etc. http://www.rubblewebs.co.uk/imagemagick ... server.php
When I did
<?php
echo "<pre>";
system("convert -version");
echo "</pre>";
?>
the output is this:
"; system("convert -version"); echo ""; ?>

But really, I don't know what I'm doing - I'm just sticking the php stuff in a webpage and publishing it. Is that right?

Bonzo wrote: You did change this to a valid image somewhere ?
http://www.website.com/input_image.jpg e.g. http://www.rubblewebs.co.uk/imagemagick ... flower.jpg
Yup, I did. Thanks.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: resizing an image without saving it

Post by Bonzo »

You need to put the php code on a page and save it as a .php page not a .htm page
lola

Re: resizing an image without saving it

Post by lola »

Bonzo wrote:You need to put the php code on a page and save it as a .php page not a .htm page
Right. Of course. Sorry.

I still get the same result though. :(
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: resizing an image without saving it

Post by Bonzo »

What are you running the code on?
lola

Re: resizing an image without saving it

Post by lola »

Bonzo wrote:What are you running the code on?
My test files are on the same server as the rest of the website... it's a Microsoft Windows Server 2003. Is that what you're asking?

I'm sorry I'm asking such stupid questions... I'm really new at this.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: resizing an image without saving it

Post by Bonzo »

Windows may be a problem as not all windows servers have php they use asp or they do not impliment it fully.

I do not know much about the windows server I am afraid.

I will have to think about it. Do you hosts say you have php installed ?
lola

Re: resizing an image without saving it

Post by lola »

Bonzo wrote:Windows may be a problem as not all windows servers have php they use asp or they do not implement it fully.

I do not know much about the windows server I am afraid.

I will have to think about it. Do you hosts say you have php installed ?

Well, there's a php.exe on the server's C: drive, and most of our website is run on php, so I'm pretty sure yes.
Maybe I'll see if there's someone around here who can help me with the php stuff, and then see if the nice little IM thingie you gave me works. :)
Thank you!
Acestes

Re: resizing an image without saving it

Post by Acestes »

I can try and help you with the PHP. I don't really know it but I think I know enough to do what you want to do. I also run PHP with ImageMagick on a Windows server running IIS. If you want I could put a little guide together saying how to install PHP with ImageMagick on a windows IIS server. Actually thinking about it do you know if the server is running IIS or Apache?
Post Reply