Page 1 of 2
resizing an image without saving it
Posted: 2008-01-02T10:26:35-07:00
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!
Re: resizing an image without saving it
Posted: 2008-01-02T12:20:53-07:00
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.
Re: resizing an image without saving it
Posted: 2008-01-02T12:51:15-07:00
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.
Re: resizing an image without saving it
Posted: 2008-01-02T13:01:13-07:00
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
Re: resizing an image without saving it
Posted: 2008-01-02T14:44:30-07:00
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>";
?>
Re: resizing an image without saving it
Posted: 2008-01-02T15:24:15-07:00
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.
Re: resizing an image without saving it
Posted: 2008-01-03T10:35:53-07:00
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.
Re: resizing an image without saving it
Posted: 2008-01-03T10:53:14-07:00
by lola
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?
Yup, I did. Thanks.
Re: resizing an image without saving it
Posted: 2008-01-03T12:01:21-07:00
by Bonzo
You need to put the php code on a page and save it as a .php page not a .htm page
Re: resizing an image without saving it
Posted: 2008-01-03T12:04:52-07:00
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.
Re: resizing an image without saving it
Posted: 2008-01-03T12:09:49-07:00
by Bonzo
What are you running the code on?
Re: resizing an image without saving it
Posted: 2008-01-03T12:29:49-07:00
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.
Re: resizing an image without saving it
Posted: 2008-01-03T12:36:25-07:00
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 ?
Re: resizing an image without saving it
Posted: 2008-01-03T13:32:54-07:00
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!
Re: resizing an image without saving it
Posted: 2008-01-03T14:38:30-07:00
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?