klykken
asked on
Imagemagick
I have a server running PHP 4.0.6.
ImageMgick was just installed on it, and I am trying to do the following:
1. Upload an image through a form.
2. Have Imagemagick resize/convert the img to a 200px wide jpg.
3. Save the image to folder/image.jpg , and doing that replacing the image.jpg that was already there.
Can all this be done from one php file, and what would this php look like?
I know this might seem to be a lot of work, but I know so little about php.
ImageMgick was just installed on it, and I am trying to do the following:
1. Upload an image through a form.
2. Have Imagemagick resize/convert the img to a 200px wide jpg.
3. Save the image to folder/image.jpg , and doing that replacing the image.jpg that was already there.
Can all this be done from one php file, and what would this php look like?
I know this might seem to be a lot of work, but I know so little about php.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks :-)
klykken
klykken
I don't have the code in front of my, but I will try to explain as good as I can.
Step 1 :
/* Generate the name of the file you want to convert
to. Extension is important for the convert-tool */
$newFile = "nameofnewfile.jpg";
/*use GetImageSize to get the width and height of your uploaded file.*/
$size = getimagesize($uploadedFile
$width = $size[0];
/* Getting size of the converted image relativ to
original - percentage */
$convertedSize = ceil((200 / $width)*100);
/*
// Now we should call the convert executable file.
// ImageMagick will now convert the $uploadedFile to a
// converted file;
// $path = the relative path from where we're standing to
// where convert is located.
*/
exec("$path/convert geometry $convertedSize% $uploadedFile $newFile);
Then you could use the $newFile instead of $uploadedFile
Hopefully this could help you!
Batalf