aldrin151
Posts: 11
|
| Posted: 12/31/2009, 4:54 PM |
|
Hi, I was reading the posts on solutions on creating a thumbnail once uploading an image. Here's one I wrote that incorporates into the events of CCS 4.X.
Simply insert below code into AfterProcessFile of FileUpload component and modify "yourform" and FileUpload component name if different. Note you must have GD 2.0
if ($yourform->FileUpload->Value <> "")
{
$path = "../thumbimages/";
$new_file = "../thumbimages/" .$yourform->FileUpload->GetValue();
list($width, $height) = getimagesize($new_file);
$newwidth = 100; // set image width
$newheight = 60; // set image height
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($new_file);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, $path.$new_file, 100);
}
I cannot imagine an easier way to do this...have fun.
|
 |
 |
damian
Posts: 838
|
| Posted: 12/31/2009, 7:11 PM |
|
please forgive my inability to get the above working!
would you please be able to add some more detail as to file paths etc - i tried all the combinations i could think of and i cant get this to work and im not getting any errors...
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
aldrin151
Posts: 11
|
| Posted: 01/02/2010, 2:24 AM |
|
Just start off creating a new page with your form and insert a FileUpload component within that form. Check in the FileUpload properties and clear any comment in the Temporary Folder section and File Folder is your path to where you'll be uploading your images...so for example in this case would type in../thumbimages
Then just place this code in the AfterProcessFile event of the FileUpload component...
if ($yourform->FileUpload->Value <> "")
{
$path = "../thumbimages/"; // Path where you'll be uploading your images
$new_file = "../thumbimages/" .$yourform->FileUpload->GetValue(); // Path where the file is retrieved to be resized
list($width, $height) = getimagesize($new_file);
$newwidth = 100; // set image width
$newheight = 60; // set image height
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($new_file);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, $path.$new_file, 100);
}
Let me know if this helps....
|
 |
 |
|