[ciapug] images

Dave J. Hala Jr. dave at 58ghz.net
Fri Aug 4 08:56:22 CDT 2006


Blake, thanks for the function. I'm using it and it works great!!!
Tweaking these images on the upload is a great idea.

I do these boring data entry and reporting forms all day long. Its nice
to do something *new* for a change.

Can I return the favor you by recommending a dog for you to adopt?

:) Dave


On Thu, 2006-08-03 at 13:45, Blake Norrell wrote:
> Heres a function I used to handle file uploads for a car site I work on.
>  It will resize the image (and keep the aspect ratio) based on the $w
> and $h parameters passed to it.  The $img field is just
> $_FILES['uploaded_file_name']['tmp'].  If the image being uploaded
> (120x90) is actually smaller than the parameters entered (say 400x300),
> it will create a new image (400x300) with the original now centered on a
> white background:
> 
> function createImage($img,$w,$h)
> {
>    $dx=$dy=0;
>    $imagedata = getimagesize($img);
>    if($imagedata[0]>$w && $imagedata[1]>$h){
>      if ($w && ($imagedata[0] < $imagedata[1])) 
>      {
>        $dw = ($h / $imagedata[1]) * $imagedata[0];
> 	   $dh=$h;
>      }
>      else 
>      {
>        $dh = ($w / $imagedata[0]) * $imagedata[1];
> 	   $dw=$w;
>      }
>    } else {
> 	 $dx=(0.5*$w)-(0.5*$imagedata[0]);
> 	 $dy=(0.5*$h)-(0.5*$imagedata[1]);
> 	 $dw=$imagedata[0];
> 	 $dh=$imagedata[1];
>    }
>    $im2 = ImageCreateTrueColor($w,$h);
>    imagefill($im2, 0, 0, 0xFFFFFF);
>    $image = ImageCreateFromJpeg($img);
>    imagecopyResampled ($im2, $image, $dx, $dy, 0, 0, $dw, $dh,
> $imagedata[0], $imagedata[1]);
>    ImageJpeg($im2, "$my_new_img, 70);
>    imagedestroy($im2);
>    imagedestroy($image);
> }	
> 
> 
> >>> Tony Bibbs <tony at tonybibbs.com> 8/3/2006 12:43 pm >>>
> Good points.  I believe that library enforces keeping the aspect ratio,
> 
> too.
> 
> --Tony
> 
> David Champion wrote:
> > I would resize the image at upload time (using something like what
> Tony 
> > posted). Be careful of aspect ratio - the uploader I've used (in 
> > vbscript - sorry) would let you specify the vertical limit, then
> scale 
> > to keep the aspect ratio.
> > 
> > End users typically don't know / don't care about image sizes and
> such - 
> > they'll upload full resolution images from their shiny new 7mp
> camera, 
> > then complain when they take too long to load.
> > 
> > -dc
> > 
> > Dave J. Hala Jr. wrote:
> >> I'm working on a site for dog adoptions. I'd like to track some
> basic
> >> information about the dog along with its photo. An admin will upload
> a
> >> image and type in the basic information. The home page will look in
> the
> >> database and display the dogs bio for the all the homeless dogs.
> >>  
> >> My concern is regarding the image of the dog. What I want to avoid
> is
> >> having to deal with a bunch of oddly sized images, etc.  I'm
> considering
> >> putting together some criteria for the admin to use when uploading
> the
> >> image. I was considering forcing the image size using the height
> and
> >> width tags in my html. My concern is that it still leaves a lot of
> room
> >> for an admin to do some bad things.
> >>
> >> Anyone have any thoughts/experience on this issue?
> >>
> >> :) Dave
> >>
> > 
> > 
> > _______________________________________________
> > ciapug mailing list
> > ciapug at cialug.org 
> > http://cialug.org/mailman/listinfo/ciapug
> _______________________________________________
> ciapug mailing list
> ciapug at cialug.org 
> http://cialug.org/mailman/listinfo/ciapug
> 
> 
> "CONFIDENTIALITY NOTICE: This communication, including any attachments, may contain confidential information and is intended only for the individual or entity to whom it is addressed.  Any review, dissemination, or copying of this communication by anyone other than the intended recipient is strictly prohibited.  If you are not the intended recipient, please contact the sender by reply email and delete and destroy all copies of the original message."
> _______________________________________________
> ciapug mailing list
> ciapug at cialug.org
> http://cialug.org/mailman/listinfo/ciapug
-- 

Open Source Information Systems, Inc. (OSIS)
Dave J. Hala Jr., President <dave at osis.us>
641.485.1606



More information about the ciapug mailing list