Dynadot โ€” .com Transfer

Automatic image resize

SpaceshipSpaceship
Watch

stscac

A Wealth of KnowledgeVIP Member
Impact
73
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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains โ€” AI StorefrontUnstoppable Domains โ€” AI Storefront
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
 
0
•••
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;

}
 
0
•••
problem has been solved, thanks for the help (Jeff/RJ other mod can close this thread)
 
0
•••
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back