Alternative to Imagick?
Posted: 2011-03-29T01:46:44-07:00
Hi there, I have recently taken over a website for a client and their site uses Image Magick and the Imagick module to re-size and upload images.
I can add a new product to the database, the record goes in fine, as does the image file name into the MySQL database but the actual physical image does not get uploaded.
After looking at the logs it appears that although Image Magick is installed, the Imagick module is not. I have asked my hosts to add it but they say as it is on a shared hosting package they will not add it for security reasons.
Now I am new to PHP so am struggling to find al alternative on how to get these images up. Here is the code I am currently using:
I have this at the top
then the rest of the page and then
Have read that GD may be an alternative but wouldn't know where to start to be honest. Used to ASP and Windows sevrers.
Any help would be most welcome.
I can add a new product to the database, the record goes in fine, as does the image file name into the MySQL database but the actual physical image does not get uploaded.
After looking at the logs it appears that although Image Magick is installed, the Imagick module is not. I have asked my hosts to add it but they say as it is on a shared hosting package they will not add it for security reasons.
Now I am new to PHP so am struggling to find al alternative on how to get these images up. Here is the code I am currently using:
I have this at the top
Code: Select all
<?php
$uploadedfile = $_FILES['userfile']['tmp_name'];
//$uploadedfile_dimensions = getimagesize($uploadedfile);
Code: Select all
}
if(is_uploaded_file($_FILES['image']['tmp_name']))
{
$image = new Imagick($_FILES['image']['tmp_name']);
$maxWidth = 250;
$maxHeight = 250;
if(($maxWidth/$image->getImageWidth()) < ($maxHeight/$image->getImageHeight()))
$maxHeight = 0;
else
$maxWidth = 0;
$image->thumbnailImage($maxWidth, $maxHeight);
$image->writeImage($_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$product_version.'_large.jpg');
$maxWidth = 180;
$maxHeight = 180;
if(($maxWidth/$image->getImageWidth()) < ($maxHeight/$image->getImageHeight()))
$maxHeight = 0;
else
$maxWidth = 0;
$image->thumbnailImage($maxWidth, $maxHeight);
$image->writeImage($_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$product_version.'_small.jpg');
}
else if(isset($_REQUEST['product_id']) && (int)$_REQUEST['product_id'] > 0)
{
$old_product_version = $product_version - 1;
copy($_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$old_product_version.'_large.jpg', $_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$product_version.'_large.jpg');
copy($_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$old_product_version.'_small.jpg', $_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$product_version.'_small.jpg');
}
echo 'SUCCESS';
?>
Any help would be most welcome.