Trouble with PHP and ImageMagick

This is a discussion on Trouble with PHP and ImageMagick within the PHP General forums, part of the PHP Programming Forums category; Hi, I am trying to make a script that will create a thumbnail of a single file which can be ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-15-2003
deadduck
 
Posts: n/a
Default Trouble with PHP and ImageMagick

Hi, I am trying to make a script that will create a thumbnail of a single
file which can be called from another file. I found a few scripts and I have
been modifying them and I can't seem to get it to work. I know I have
imagemagick installed because when I run another script that displays all of
the images in the directory it works

i.e. http://humor.multiwebinc.com/images/index.php

The script I created is as follows:

<?php


// Specify your file details.
$current_file = 'anykey.jpg';
$max_width = '150';


// Get the current info on the file
$current_size = getimagesize($current_file);
$current_img_width = $current_size[0];
$current_img_height = $current_size[1];
$image_base = explode('.', $current_file);


// This part gets the new thumbnail name
$image_basename = $image_base[0];
$image_ext = $image_base[1];
$thumb_name = $image_basename.'-th.'.$image_ext;


// Determine if the image actually needs to be resized
// and if it does, get the new height for it
if ($current_img_width > $max_width)
{
$too_big_diff_ratio = $current_img_width/$max_width;
$new_img_width = $max_width;
$new_img_height = round($current_img_height/$too_big_diff_ratio);
}

// Convert the file
$make_magick = ("/usr/X11R6/bin/convert -geometry 120x120
anykey.jpg -resize 120x120 anykey-th.jpg");
$newfile = exec("'.$make_magick.'"); //this doesn't seem to work
exec("'.$make_magick.'"); //this doesn't seem to work either.. I've also
tried system() here too, but that doesn't do anything.

echo '<img src="anykey-th.jpg">';

// not sure if this would be necessary, but I found it on a site somewhere
and put it here for debugging purposes.
if($newfile) {
echo "<br>something happend";
copy ($newfile ,".
/home/virtual/site1/fst/home/humor/public_html/images/anykey-th.jpg.");
}
else {echo ' <br>nothing happened';}

?>

see http://humor.multiwebinc.com/images/thumbnail.php

The image anykey-th.jpg isn't even created at all when I run this script. I
have no idea why this isn't working. Can anyone help me out with this one?
Keep in mind that I really know nothing about php and have just sorta been
picking it up a bit for the past week.

Thanks a lot,

Mike Robinson


Reply With Quote
  #2 (permalink)  
Old 12-15-2003
deadduck
 
Posts: n/a
Default Re: Trouble with PHP and ImageMagick

I forgot to mention one thing, I also executed the command

convert -geometry 120x120 anykey.jpg -resize 120x120 anykey-th.jpg

via an SSH login and it worked fine.


"deadduck" <deadduck@hotpop.com> wrote in message
news:SvcDb.35165$NNW1.9866@news04.bloor.is.net.cab le.rogers.com...
> Hi, I am trying to make a script that will create a thumbnail of a single
> file which can be called from another file. I found a few scripts and I

have
> been modifying them and I can't seem to get it to work. I know I have
> imagemagick installed because when I run another script that displays all

of
> the images in the directory it works
>
> i.e. http://humor.multiwebinc.com/images/index.php
>
> The script I created is as follows:
>
> <?php
>
>
> // Specify your file details.
> $current_file = 'anykey.jpg';
> $max_width = '150';
>
>
> // Get the current info on the file
> $current_size = getimagesize($current_file);
> $current_img_width = $current_size[0];
> $current_img_height = $current_size[1];
> $image_base = explode('.', $current_file);
>
>
> // This part gets the new thumbnail name
> $image_basename = $image_base[0];
> $image_ext = $image_base[1];
> $thumb_name = $image_basename.'-th.'.$image_ext;
>
>
> // Determine if the image actually needs to be resized
> // and if it does, get the new height for it
> if ($current_img_width > $max_width)
> {
> $too_big_diff_ratio = $current_img_width/$max_width;
> $new_img_width = $max_width;
> $new_img_height = round($current_img_height/$too_big_diff_ratio);
> }
>
> // Convert the file
> $make_magick = ("/usr/X11R6/bin/convert -geometry 120x120
> anykey.jpg -resize 120x120 anykey-th.jpg");
> $newfile = exec("'.$make_magick.'"); //this doesn't seem to work
> exec("'.$make_magick.'"); //this doesn't seem to work either.. I've also
> tried system() here too, but that doesn't do anything.
>
> echo '<img src="anykey-th.jpg">';
>
> // not sure if this would be necessary, but I found it on a site somewhere
> and put it here for debugging purposes.
> if($newfile) {
> echo "<br>something happend";
> copy ($newfile ,".
> /home/virtual/site1/fst/home/humor/public_html/images/anykey-th.jpg.");
> }
> else {echo ' <br>nothing happened';}
>
> ?>
>
> see http://humor.multiwebinc.com/images/thumbnail.php
>
> The image anykey-th.jpg isn't even created at all when I run this script.

I
> have no idea why this isn't working. Can anyone help me out with this one?
> Keep in mind that I really know nothing about php and have just sorta been
> picking it up a bit for the past week.
>
> Thanks a lot,
>
> Mike Robinson
>
>



Reply With Quote
  #3 (permalink)  
Old 12-16-2003
Leveller
 
Posts: n/a
Default Re: Trouble with PHP and ImageMagick

On Mon, 15 Dec 2003 06:39:35 GMT, "deadduck" <deadduck@hotpop.com>
wrote:

>> // Convert the file
>> $make_magick = ("/usr/X11R6/bin/convert -geometry 120x120
>> anykey.jpg -resize 120x120 anykey-th.jpg");
>> $newfile = exec("'.$make_magick.'"); //this doesn't seem to work
>> exec("'.$make_magick.'"); //this doesn't seem to work either.. I've also
>> tried system() here too, but that doesn't do anything.



try:
exec($make_magick);
your quotes don't seem right to me.

If that doesn't work then you could try capturing the return code...

$returnarray=array();
$returnval=0;
exec($make_magick,$arr,$return);

Now check your return code in $returnval and print out $returnarray
using print_r($returnarray) for the feedback. This may give you some
some more info.

Another possible is file or directory permissions. Check that the
user Apache runs as has write access. This gets me every time!

Leveller


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:39 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0