Jump to content

Image Magik


deathdeyfer2002

Recommended Posts

All-

 

I'm trying to automatically resize all of the images on my webpage.  I currently have them stored in an array.  I can access the array from the following code

 

 


for ($imagecounter = 0; $imagecounter < $pic_count; $imagecounter++)
{
$currentimage = $folder[$imagecounter];
echo "<img src='/Movies/$currentimage' >";
}

 

That goes through all of the images and displays them as pictures.  I wanted to use the function from Imagemagik: mogrify .  From the command line it resized the images without any trouble using the following code

mogrify -resize 200x125 Left1.png

 

I have been trying to incorporate this into PHP to have it do this automatically.  Here is what I tried and it appears to be failing everytime

 

$command = '"mogrify -resize 468.75x200"/home/deathdefyer2002/imageA.jpg
exec($command);

 

 

Please help. 

Link to comment
https://forums.phpfreaks.com/topic/186951-image-magik/
Share on other sites

When I reload the page, It seems to be loading for a little bit but nothing new is being displayed. 

 

I entered

exec('mogrify -resize 468.75x200  /home/deathdefyer2002/imageA.jpg');

 

I am testing the code by using the following:

 

echo "<img src='/home/deathdefyer2002/imageA.jpg' >";

 

Every refresh and the image never changes.

 

 

Link to comment
https://forums.phpfreaks.com/topic/186951-image-magik/#findComment-987253
Share on other sites

try this out

 

$command = 'mogrify -resize 468.75x200 /home/deathdefyer2002/imageA.jpg';
$output = array();
exec($command, $output);
var_dump($output);

 

also this

 

echo "<img src='/home/deathdefyer2002/imageA.jpg' >";

 

is that the right path, it should a http path and not your linux path

 

 

Link to comment
https://forums.phpfreaks.com/topic/186951-image-magik/#findComment-987261
Share on other sites

I went ahead and updated the code and I still receive the following output string(0) ""

 

 

The Imgsrc line appears to be working just fine.  It IS displaying the image, but with the original dimensions.  If I run the mogrify command on the command line and refesh the page, it does change the resolution.    If you beleive that the IMG SRC could be the problem, then I will go ahead and update that to the HTML path.

 

 

Link to comment
https://forums.phpfreaks.com/topic/186951-image-magik/#findComment-987265
Share on other sites

not too sure, but could be a permission issue as your php script will run as restricted user you might even want to change the command to a absolute path like for example

 

$command = '/usr/bin/mogrify -resize 468.75x200 /home/deathdefyer2002/imageA.jpg';

 

the above is just an example your command could be located at a different location, you can find the location on the shell by typing

 

which mogrify

 

hope its helpful

that should show you the full path of the command.

Link to comment
https://forums.phpfreaks.com/topic/186951-image-magik/#findComment-987267
Share on other sites

Also, you just need one size parameter when doing resize imagemagick can figure the rest out and resize nicely!

 

you should also place your file name in single quotes:

 

Try this:

$command = "mogrify -resize x200 '/home/deathdefyer2002/imageA.jpg'"
shell_exec($command);

 

 

Link to comment
https://forums.phpfreaks.com/topic/186951-image-magik/#findComment-987273
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.