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

Re: resizing an image without saving it

Post by lola »

Acestes wrote: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?
That would be amazing!
Unfortunately, however, we're currently running Apache, but it's not working well with our SQL needs so we have a proposal in to switch to a 32-bit IIS server... I have no idea when that might happen though.
Acestes

Re: resizing an image without saving it

Post by Acestes »

I've never really used Apache, but there are loads of people around that have so I'm sure between us we can work something out. In windows there are two ways that you can access IM (imagemagick). One way is to access it via the command line interface, like this code example suggested

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);
?>
However that way requires you to open permissions up on the cmd.exe which is not recommended as it is unsecure (I can confirm if you have just installed IM and not altered any permissions on any files and folder the code above will simply not work and give you an 'image missing' icon) The second is to install the imagick module for windows which allows php to access IM without leaving your system quite so insecure (this is the method I use). Let me know which way you want to go and I'll try and guide you though it :D
lola

Re: resizing an image without saving it

Post by lola »

Acestes wrote:I've never really used Apache, but there are loads of people around that have so I'm sure between us we can work something out. In windows there are two ways that you can access IM (imagemagick). One way is to access it via the command line interface, like this code example suggested

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);
?>
However that way requires you to open permissions up on the cmd.exe which is not recommended as it is unsecure (I can confirm if you have just installed IM and not altered any permissions on any files and folder the code above will simply not work and give you an 'image missing' icon) The second is to install the imagick module for windows which allows php to access IM without leaving your system quite so insecure (this is the method I use). Let me know which way you want to go and I'll try and guide you though it :D
Man, this is a lot more complicated than I had anticipated!
It's definitely best to go with the more secure route, I think. Is it a lot more complicated?
Thanks!
Acestes

Re: resizing an image without saving it

Post by Acestes »

Personally I don't think the secure root is any more difficult (now I know how to do it! :D). What you need to do is the following;

1) Install the latest version of imageMagick (Make sure it is installed to a directory without spaces as some users have reported problems when using directories with spaces. E.g. 'C:\imagemagick' rather than C:\program files\imagemagick')

2) Get the latest windows binary build of the 'dynamic' imagick dll from here http://valokuva.org/?page_id=50 If you don't know which to pick choose the one called 'php_imagick_dyn-Q8.dll' as that is fine for web use and uses less system resources.

3) Place the imagick dll you just downloaded with all the other php extensions (usually something like 'c:\php\ext', there will be loads of them under there). Make sure it has the same security permissions that the other dll files have. IIS specifically needs 'Internet Guest Account (MACHINENAME\IUSR_MACHINENAME)'. I don't know what user Apache runs as so it's best to just make sure it's the same as the others.

4) Install the visual studio 2005 c++ SP1 redistributable package from here http://www.microsoft.com/downloads/deta ... 9c36f85647 if you don't already have it (which you probably don't). You will need it, it took me several hours to find out I was missing this as the errors that PHP gives are not clear this is what is needed!

5) Edit your php.ini file (this is normally under 'c:\windows\php.ini' and can be edited with notepad) by adding a line to the 'dynamic extensions' section to point to the imagick dll, it will look something like this

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;

....
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.


;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
....
where we add the line

Code: Select all

extension=php_imagick_dyn-Q8.dll
so it looks something like this (Note: the extension must NOT have a ';' in front of it as that stops PHP from loading it!)

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;

....
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.

extension=php_imagick_dyn-Q8.dll
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
....
6) Reboot Apache so that the changes to the php.ini file are taken into account.

7) Run the PHP info code. If you don't know how to do this create a PHP file with the following code in it and run it from a browser

Code: Select all

<?php phpinfo(); ?> 
this will then give you information on all the modules that PHP is running, as well as some other very useful information. Scroll down the list and look for the block called 'imagick'. Hopefully if all has gone well you'll see it listed :)

Finally!!!

Sit back and relax as PHP should now be able to run IM via the imagick module. For now I'll leave it there as I think though we should get the above working first! Don't worry the next bit is really really easy :D
lola

Re: resizing an image without saving it

Post by lola »

Acestes wrote:Personally I don't think the secure root is any more difficult (now I know how to do it! :D). What you need to do is the following;

1) Install the latest version of imageMagick (Make sure it is installed to a directory without spaces as some users have reported problems when using directories with spaces. E.g. 'C:\imagemagick' rather than C:\program files\imagemagick')
Well, I got this far, but in the setup instructions it says to test it:
"You have now installed ImageMagick. To test the installation select Command Prompt from the Windows Start menu. Within the window type:
convert logo: logo.miff
imdisplay logo.miff"

When I do that it says the file is not found.
Is that a problem? Could it have something to do with the fact that I installed on the F drive (because that's where all the other applications as well as the website pages live) but it's looking for that file on the C drive? Or does that not matter?

Thanks so much for your detailed post... I'm really looking forward to getting this working!! :)
Acestes

Re: resizing an image without saving it

Post by Acestes »

Hmm... it's a little worrying that you can't even get that to work! :D

What I would suggest is run the convert command

Code: Select all

convert logo: logo.jpg
and just check that the file 'logo.jpg' has been created (it'll be under the imagemagick installation folder). If that doesn't work it could be because of a permissions problem not letting imagemagick save the logo, which is why when you try and display it through the 'imdisplay' command it can't find the file. However if it is there then I have no idea! It could be worth trying to install it on the c:\ drive though just in case that is a problem (although I can't see why it should be, but I also can't say I've tried it)
Post Reply