CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Automatic Thumbnail Creation using CCS FileUpload made simple.

Print topic Send  topic

Author Message
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. :-D
View profile  Send private message
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.... :)
View profile  Send private message
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....
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.