I have an user defined amount of files (images) being uploaded. They are moved to the appropriate folder for the stock number of the car. I want the image to be resized to a size and then the file copied and resized as a thumbnail.
I am having problems with the resizing of the thumbnail. Also, the first file, which resizes appropriately is being deleted.
I attempted this with commands other than that of $cmdText, but PHP is version 4.2 and has not been compiled with the proper GD.
I don't have any experience using shell commands, but I am assuming that this is one:
$cmdText = "convert -size 320x240 $dir -resize 320x240 +profile '*' $dir ";
Which, seems to work fine with the resizing to 320x240. I would not be suprised if there are unnecessary things in there - I don't know how that works. I copied that line from code that the guy that maintains our servers wrote, I assume that this was his was of getting around the image restrictions of our version of php and gd.
The next $cmdtext is a feeble attempt at hoping that a miracle occurs and the command works. This is for the thumbnail.
convert -size 80x60 $dir -resize 80x60 +profile '*' $thumb_dir
The key difference here was my assumption that what follows '*' may be the same as the part of move uploaded file, where you say where the file is to be moved.
This is not the case, and therefore I am here hoping someone can help!!
All images will be landscape, and jpeg.
A relevant portion of the code I am using is:
for($i = 1; $i <= $amount; $i++){
unset($size320);
unset($name);
unset($dir);
unset($directory);
unset($thumb_dir);
$name = 'image_' . $i;
$directory = $directory1 . $name;
$thumb_dir = $directory1 . $name . '_thumb';
$dir = $directory . '.jpg';
$thumb_dir = $thumb_dir . '.jpg';
if(isset($_FILES[$name])){ //If the file exists
if (move_uploaded_file($_FILES[$name]['tmp_name'], $dir)){
$cmdText = "convert -size 320x240 $dir -resize 320x240 +profile '*' $dir ";
system($cmdText, $cmdStatus);
unset($cmdText);
if( $cmdStatus ) {
$fail[] = 'Could not resize original image to 320x240 ( Image ' . $i . ' )';
unset($cmdStatus);
}else{
$success[] = 'Image ' . $i . ' successfully resized to 320x240.';
$size320 = 1;
}
if($size320 == 1){
$cmdText = "convert -size 80x60 $dir -resize 80x60 +profile '*' $thumb_dir ";
system($cmdText, $cmdStatus);
unset($cmdText);
if( $cmdStatus ) {
$fail[] = 'Could not resize original image to 80x60 ( Image ' . $i . "[$cmdStatus] )";
unset($cmdStatus);
}else{
$success[] = 'Image ' . $i . ' successfully resized to 80x60.';
}
}
$success[] = 'Image ' . $i . ' Uploaded.';
}else{
$fail[] = 'Image ' . $i . ' Not uploaded.';
}
}else{
$errors[] = 'File does not exist.';
}
}
Thankyou.
I am sure there are things in the code above that can be done much better, i'm learning.