[ciapug] images
Blake Norrell
BNorrell at ifmc.org
Thu Aug 3 13:45:45 CDT 2006
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."
More information about the ciapug
mailing list