Forum Moderators: coopster
I currently have to deal with all the uploading of product pictures myself. I would like to add to my back end PHP program the functions to allow my employees to do it.
So I will need to be able to have a program that does several processes that I currently do manually. I need a program that will run on my unix server that I can call by command line and it will
1. Resize the picture. I need to 2 copies. One that is max 350 x 350 and a thumbnail that is 100 x 100. Keeping tha aspect ratio correct
2. Optimize the graphic for fast loading
Does anyone know of a program like this?
- Ryan
Not sure if you need this part, but, for the uploading on the input form page, I have this:
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
<input name="uploadimage" type="file" />
Which has something like this on the "page" that processes that form input:
if ($uploadimage<>"")
{
$uploaddir = '/your/picture/diretory/';
$uploadfile = $uploaddir . basename($_FILES['uploadimage']['name']);
move_uploaded_file($_FILES['uploadimage']['tmp_name'], $uploadfile);
$uploadedimagename = basename($uploadfile);
$image = $uploadedimagename;
}
So then you have an image on your server to work with.
This function will create a thumbnail and it can be modified to resize an image, also (just change the dimensions).
function createthumb($name,$filename,$new_w,$new_h){
global $gd2;
$system=explode(".",$name);
if (preg_match("/jpg¦jpeg/",$system[1])){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match("/png/",$system[1])){
$src_img=imagecreatefrompng($name);
}
I'd just post a link to the tutorial but I think that's frowned upon here. In the meantime, look at the manual for "imagecreatefromjpeg".