Page 1 of 1

Posted: 2006-05-20T08:24:28-07:00
by Bonzo
I would try something simpler first bluecrisis without using user input and see if it works then build that into your code.

I have also seen that you probably need the path to ImageMagick in the line:

Code: Select all

exec("convert -size 500x180" . $_FILES['imgfile']['tmp_name'] ." -thumbnail 250x90 ".$_FILES['imgfile']['name']) or die('error'); 
Wants to be something like:

Code: Select all

exec("/usr/local/bin/convert -size 500x180" . $_FILES['imgfile']['tmp_name'] ." -thumbnail 250x90 ".$_FILES['imgfile']['name']) or die('error'); 
You could ask your hosts what the path to ImageMagick is it could just be /user/bin/.

Also this line is not a php line so you would need to lose all the ". ?

Code: Select all

exec("/usr/local/bin/convert -size 500x180 $_FILES['imgfile']['tmp_name']  -thumbnail 250x90 $_FILES['imgfile']['name']") or die('error'); 
I used to convert the $_FILES['imgfile']['tmp_name'] to a variable then use the new variable in the exec code.

I may be wrong about some of this but I have not used ImageMagick for a few years now !

Anthony

Posted: 2006-05-21T02:27:46-07:00
by Bonzo
The problem with ImageMagick and shell is that from what I understand it does not return any error messages.

You probably know as much about ImageMagick as me now but I will have a look later today and see if I can see anything !

Anthony

Posted: 2006-05-21T04:16:28-07:00
by Bonzo
I have tried your code on my server and all I get is the error message.

I had to modify this line :

Code: Select all

$convert = '/homepages/----/htdocs/ImageMagick-6.2.7/bin/convert -size x'.(imgHeight*2).' '.$srcimg.' -thumbnail x'.$imgHeight.' '.$destimg; 
To this as you only have the height and not the width and a $ is missing.

Code: Select all

$convert = '/homepages/----/htdocs/ImageMagick-6.2.7/bin/convert -size '.($image_info[0]).'x'.($image_info[1]).' '.$srcimg.' -thumbnail '.$imgHeight.'x'.$imgHeight.' '.$destimg; 

I will have another look when I get a bit more time.

Anthony

Posted: 2006-05-21T05:00:12-07:00
by Bonzo
Try this :

Code: Select all

$convert = '/homepages/----/htdocs/ImageMagick-6.2.7/bin/convert -size '.$image_info[1].' '.$srcimg.' -geometry  '.$imgHeight.' '.$destimg; 
I am not sure but when I hard coded the paths etc into the $convert line it worked OK but when using variables it seemed to fail although I have tried loads of changes and started to lose track!

Anthony

Posted: 2006-05-21T06:48:41-07:00
by Bonzo
I have done some more tests and it is strange that this will work:

Code: Select all

$original_image = "earth.jpg";
$size=GetImageSize( $original_image );
$new_image = "new2.jpg";
$max_width = "200";
$max_height = "90";
exec("/usr/bin/composite -size 733x567 $original_image -thumbnail $max_widthx$max_height $new_image");
But this won't:

Code: Select all

$original_image = "earth.jpg";
$size=GetImageSize( $original_image );
$new_image = "new2.jpg";
$max_width = "200";
$max_height = "90";
exec("/usr/bin/composite -size $size[0]x$size[1] $original_image -thumbnail $max_widthx$max_height $new_image");
Anthony

Posted: 2006-05-21T11:33:06-07:00
by ridera
The exec() expects a string. So the array[] won't work directly.

Try it braces i.e., {$size[0]x$size[1]}. It may work.

Posted: 2006-05-21T11:44:10-07:00
by Bonzo
This seemed to work OK ridera.

{$size[0]}x{$size[1]}

Anthony

Posted: 2006-05-22T10:59:11-07:00
by Bonzo
I have rewritten your code bluecrisis and it should now work; I didn't do this before but should have done sorry.

It was not uploading and resizing the image as you didn't have the filename in the getimagesize so the code would have failed there.
Trying the code out on my server as you say you get the error returned anyway if the code works or not.

When doing things like this put some echo comands in the code and you can see what is happening - I have left them in the code below so you can see what I mean. It is ideal for checking wat the values of the variables are.

Anthony

Code: Select all

<?php 

if(isset($_POST['submit']) && strcmp($_POST['submit'],'submit')==0){ 
$defaultImgHeight = 250; 
echo "<br>tempory_image = ".$_FILES['imgfile']['tmp_name']."<br>";
echo $_FILES['imgfile']['name']."<br>";
if($image_info = getimagesize($_FILES['imgfile']['tmp_name'])){ 
if( $image_info[0] > $defaultImgHeight ){ 
//exec("convert -size 500x180" . $_FILES['imgfile']['tmp_name'] ." -thumbnail 250x90 ".$_FILES['imgfile']['name']) or die('error'); 
$original_image = $_FILES['imgfile']['tmp_name'];
echo "<br>original_image = ".$original_image."<br>";
$new_image = $_FILES['imgfile']['name'];
echo "<br>new_image = ".$new_image."<br>";
$max_width = 250;
exec("/usr/local/bin/convert -size {$image_info[0]}x{$image_info[1]} $original_image -thumbnail $max_widthx$defaultImgHeight $new_image")or die('error');  
} 
} 
} 
?> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<title>IM Test</title> 
</head> 

<body> 
<form name="imtest" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data"> 
<input type="file" name="imgfile"> 
<input type="submit" name="submit" value="submit"> 
</form> 
</body> 
</html>