MagickWriteImage fails (sometimes)

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
eholz1
Posts: 10
Joined: 2007-02-04T20:18:17-07:00

MagickWriteImage fails (sometimes)

Post by eholz1 »

Hello Magickwand group,
I have a perplexing problem. I am using Fedora Core 6, PHP 5.2, and apache 2.2.
I have Magicwand, Imagemagick, and GD in my php config.

I have two php pages, one where I read an image(s) and size(s), and resize the image, and do a write to a diff path (reads from testimage/mypix.jpg, and writes to 25/mypix.jpg)
$magick_wand = NewMagickWand();
MagickReadImage($magick_wand,$image);

$resizedImage = MagickTransformImage( $magick_wand, '0x0',"$size");
MagickSharpenImage($resizedImage, 0.0,1.0);
MagickWriteImage($resizedImage,$newpath);

in a loop, image by image, this works every time. I read a file in one directory, and then write it to
another directory in its "resized" format.

Then I have a page that reads the resized file, and then transforms the image to a thumbnail,
and writes it (supposed to write it!) to a different directory.
Code snippet:

function thumbMaker($id,$mod,$image)
{
$magick_wand = NewMagickWand();
$name = explode('/',$image);
$path = $mod .'/'. 'thumbs' . '/' . 'tn_'. \"".$name[1].\"";

$update = "UPDATE images3 SET thmbpath = " . "'". $path . "'" . " WHERE modfolder = $mod AND id = $id";
@mysql_query($update) or trigger_error("Error Perfoming Query: ". mysql_error(), E_USER_ERROR);

MagickReadImage($magick_wand,$image);
$thumbImage = MagickTransformImage( $magick_wand, '0x0', '150x150' );
MagickWriteImage($thumbImage,$path);
}

The mysql part seems to work fine. I pass the image name, id, etc to the function.
the image is read from one path (25/mypix.jpg), and supposed to be written to another path (25/thumbs/tn_mypix.jpg
this code seems the same as the sample above. I have played around with the permissions on the folders (apache.apache, the web user) and even tried setting privs for "all" to rw (do I need execute?)

the code that reads (on a diff php file) the base file, and writes a resized version of the file works fine.
It is when I read the resized file, and try to write the thumbnail, the MagickWrite command fails.

Any guidance on this will help.

thanks you ,

eholz1
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickWriteImage fails (sometimes)

Post by magick »

Add a few MagickGetExceptionString() methods to your code to report any exceptions you are receiving. It should provide enough insight to fix the problem.
eholz1
Posts: 10
Joined: 2007-02-04T20:18:17-07:00

Re: MagickWriteImage fails (sometimes)

Post by eholz1 »

Yes, I will do that. should be there anyway!!!!
Thanks,

eholz1
eholz1
Posts: 10
Joined: 2007-02-04T20:18:17-07:00

Re: MagickWriteImage fails (sometimes)

Post by eholz1 »

Hello PHP/Magic wand
I discovered my problem. It turns out that MagickWandWrite, etc is VERY sensitive
to having incorrect permissions on folders and files! This issue, sadly, I created.
I am still not quite sure how to set permissions appropriately, but it seems if I have
apache as the owner, and a group (either apache or my special group webdev) set for read/write
and create/delete files, this will allow magicwand to write images, etc.

I am assuming since I am running apache on linux with php, the user is apache.

Thanks,

eholz1
squig

Re: MagickWriteImage fails (sometimes)

Post by squig »

Hello,

I just run into this posting, you know or you think that your apache runs as user "apache"?

Have a look at "httpd.conf", the apache configuration file. This is were apache user and group are defined.
Search there for "User" and "Group" to find the actual values. You can change them to whatever you want but be sure user and group exists. Also remember to restart apache to see changes.


Squig
Post Reply