| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| A Wealth of Knowledge Join Date: Aug 2004
Posts: 3,809
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | |
| |
| | #2 (permalink) |
| NamePros Regular Join Date: Jun 2003 Location: Louisiana, USA
Posts: 658
![]() ![]() | 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 |
| |
| | THREAD STARTER #3 (permalink) |
| A Wealth of Knowledge Join Date: Aug 2004
Posts: 3,809
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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;
} |
| |