[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 02-25-2005, 10:03 PM   #1 (permalink)
A Wealth of Knowledge
 
stscac's Avatar
 
Join Date: Aug 2004
Posts: 3,794
47.60 NP$ (Donate)

stscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud of


Caution automatic image resize

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
stscac is offline  
Old 02-25-2005, 10:50 PM   #2 (permalink)
NamePros Regular
 
Join Date: Jun 2003
Location: Louisiana, USA
Posts: 665
33.75 NP$ (Donate)

painperdu has a spectacular aura aboutpainperdu has a spectacular aura about


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
__________________
******dotbob.com******
Cheap Domain Name Registrations
**** -Dotbob.com
painperdu is offline  
Old 02-25-2005, 11:05 PM   #3 (permalink)
A Wealth of Knowledge
 
stscac's Avatar
 
Join Date: Aug 2004
Posts: 3,794
47.60 NP$ (Donate)

stscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud of


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;

}
stscac is offline  
Old 02-27-2005, 12:13 PM   #4 (permalink)
A Wealth of Knowledge
 
stscac's Avatar
 
Join Date: Aug 2004
Posts: 3,794
47.60 NP$ (Donate)

stscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud ofstscac has much to be proud of


problem has been solved, thanks for the help (Jeff/RJ other mod can close this thread)
stscac is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 02:41 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85