| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| A Wealth of Knowledge | i am in the process of building a site for a client and need a quick solution. my goal: to automatically change the file size (meaning actual dimension, so it is dial-up friendly an reduced to look good on a page) of a jpg when it is uploaded through a web interface into a specific folder. I know you can do this through gd. Say the 2.2mb file is uploaded to the folder "gallery". When it is stored on the server, I want it to be reduced in size, based on percentages or original size (like 10% by 10% of original size) and stored as the same filename as it was uploaded. Please don't recommend me using another gallery script, I am locked into using this one. Any other help as to how to do this would be greatly appreciated. Steve |
| |
| | #2 (permalink) |
| NamePros Regular | What language are you working with? In PHP it's not that hard to do -just a few steps in between uploading, renaming, getting dimensions, change dimensions, and copying to a directory. PHP image functions: http://www.php.net/manual/en/ref.image.php |
| |
| | #3 (permalink) |
| A Wealth of Knowledge | my project is in php, but in am not a "coder" it is a script that i want customized just a little. My main purpose is to have the image be resized when it hits (or before) the destination folder, is there any other way to do that (that i would understand) The following seems like something that i could use. But where would I put it so it would resize the files automatically? Code: /* resizeToFile resizes a picture and writes it to the harddisk
*
* $sourcefile = the filename of the picture that is going to be resized
* $dest_x = X-Size of the target picture in pixels
* $dest_y = Y-Size of the target picture in pixels
* $targetfile = The name under which the resized picture will be stored
* $jpegqual = The Compression-Rate that is to be used
*/
function resizeToFile ($sourcefile, $dest_x, $dest_y, $targetfile, $jpegqual)
{
/* Get the dimensions of the source picture */
$picsize=getimagesize("$sourcefile");
$source_x = $picsize[0];
$source_y = $picsize[1];
$source_id = imageCreateFromJPEG("$sourcefile");
/* Create a new image object (not neccessarily true colour) */
$target_id=imagecreatetruecolor($dest_x, $dest_y);
/* Resize the original picture and copy it into the just created image
object. Because of the lack of space I had to wrap the parameters to
several lines. I recommend putting them in one line in order keep your
code clean and readable */
$target_pic=imagecopyresampled($target_id,$source_id,
0,0,0,0,
$dest_x,$dest_y,
$source_x,$source_y);
/* Create a jpeg with the quality of "$jpegqual" out of the
image object "$target_pic".
This will be saved as $targetfile */
imagejpeg ($target_id,"$targetfile",$jpegqual);
return true;
}
|
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |