Here a code snippet for you to generate Thumbnails by RSForm Upload fields. Put this code in the Script section. Change the URL to set your own upload location. You can also set the width an height of thumbnails. This script generates 6 Thumbnails because i used 6 upload fields in my RsForm Pro Form. Gd library must be available on your webhost or server.
$allPics = 6;
for($picNumb = 1; $picNumb <= $allPics; $picNumb++)
{
$fileName = '{Fahrzeugbild'.$picNumb.':filename}';
list($replace, $with) = RSFormProHelper::getReplacements($SubmissionId);
$fileName = str_replace($replace, $with, $fileName);
/*
* Resize and center crop an arbitrary size image to fixed width and height
* e.g. convert a large portrait/landscape image to a small square thumbnail
*/
define('DESIRED_IMAGE_WIDTH', 108);
define('DESIRED_IMAGE_HEIGHT', 72);
/* $source_path = $_FILES['Image1']['tmp_name']; */
$source_path = $_SERVER['DOCUMENT_ROOT'].'/xxxxxxxxxxxxxxx/components/com_rsform/uploads/fahrzeuge/'.$fileName;
/*
* Add file validation code here
*/
list($source_width, $source_height, $source_type) = getimagesize($source_path);
switch ($source_type) {
case IMAGETYPE_GIF:
$source_gdim = imagecreatefromgif($source_path);
break;
case IMAGETYPE_JPEG:
$source_gdim = imagecreatefromjpeg($source_path);
break;
case IMAGETYPE_PNG:
$source_gdim = imagecreatefrompng($source_path);
break;
}
$source_aspect_ratio = $source_width / $source_height;
$desired_aspect_ratio = DESIRED_IMAGE_WIDTH / DESIRED_IMAGE_HEIGHT;
if ($source_aspect_ratio > $desired_aspect_ratio) {
/*
* Triggered when source image is wider
*/
$temp_height = DESIRED_IMAGE_HEIGHT;
$temp_width = ( int ) (DESIRED_IMAGE_HEIGHT * $source_aspect_ratio);
} else {
/*
* Triggered otherwise (i.e. source image is similar or taller)
*/
$temp_width = DESIRED_IMAGE_WIDTH;
$temp_height = ( int ) (DESIRED_IMAGE_WIDTH / $source_aspect_ratio);
}
/*
* Resize the image into a temporary GD image
*/
$temp_gdim = imagecreatetruecolor($temp_width, $temp_height);
imagecopyresampled(
$temp_gdim,
$source_gdim,
0, 0,
0, 0,
$temp_width, $temp_height,
$source_width, $source_height
);
/*
* Copy cropped region from temporary image into the desired GD image
*/
$x0 = ($temp_width - DESIRED_IMAGE_WIDTH) / 2;
$y0 = ($temp_height - DESIRED_IMAGE_HEIGHT) / 2;
$desired_gdim = imagecreatetruecolor(DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT);
imagecopy(
$desired_gdim,
$temp_gdim,
0, 0,
$x0, $y0,
DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT
);
header('Content-type: image/jpeg');
/* imagejpeg($desired_gdim); */
/* save pic to destination folder */
imagejpeg( $desired_gdim, $_SERVER['DOCUMENT_ROOT'].'/xxxxxxxxxxxxxxxxx/components/com_rsform/uploads/fahrzeuge/thumbs/'.$fileName );
}