Forum Moderators: not2easy
A. Have script that will automactically reduce the size of the photo pixels if too large and compress the photo if the file is too big; or
B. Only allow images of a certian file size and only allow images that are of a certain pixel size - if the file size or image size are too big then an error massage is sent to the user.
On one site I placed a link to Irfanview [irfanview.com] for those clients that needed a freeware image program.
jb
As far as which method to choose...
a.) Never require people to think! Let them upload whatever they want and then set-up GD to resize the image for them.
b.) If you have limited funds/experience/time then go ahead and tell the real estate folks to resize and compress their images. My experience tells me this is a very bad idea though.
Here's another thread that dealt with this very issue [webmasterworld.com]
Thanks. I have tried using Coldfusion CFX_Image, however the quality or compression does not work at all so the picture quality comes out really bad.
The hosting service is use does offer the imageMagic PHP component and i am going to try that next. I would love to see the code on how you do it since i am a Coldfusion guy and not a PHP type of guy - is there anyway i can peek at your code for the file upload and resize?
<?php
/*
Resize an image using GD
*** NOTE - REQUIRES GD 2.0 OR HIGHER ***
------------------------------------------------------------------------
$Image is a string path to an image on the disk
$NewWidth is the maximum width you will allow for the image
$NewHeight is the maximum height you will allow for the image (optional)
$DestImage is the filename of the output default is to over-write the old image (optional)
------------------------------------------------------------------------
The function will figure out which dimension already fits in your specifications and size the image accordingly.
The web server needs to have write privileges to the image and/or directory where the output goes.
Returns true on success, false on failure
*** Examples ***
resizeImage("test.jpg",400); // Fit the width to 400 pixels
resizeImage("test.jpg",400,400); // Fit the width to 400 pixels, height to 400 pixels
resizeImage("test.jpg",400,0,"newimage.jpg"); // Fit the width to 400 pixels, height doesn't matter, output to newimage.jpg
*** NOTE - If you specify the last argument (output filename), you must put a height value in (0 if you don't want to do a height). ***
*/
function resizeImage($Image,$NewWidth,$NewHeight = 0,$DestImage = "")
{
// Get the original image info
list ($OrigWidth,$OrigHeight,$OrigType) = getimagesize($Image);
// Figure out how to resize the image
if ($NewHeight)
{
if (($OrigWidth - $NewWidth) >= ($OrigHeight - $NewHeight))
{
$Width = $NewWidth;
$Height = floor(($NewWidth / $OrigWidth) * $OrigHeight);
}
else
{
$Height = $NewHeight;
$Width = floor(($Height / $OrigHeight) * $OrigWidth);
}
}
else
{
$Width = $NewWidth;
$Height = floor(($NewWidth / $OrigWidth) * $OrigHeight);
}
// Create a new blank image based on the image type
if ($OrigType == 1) // GIF
{
$OrigImage = ImageCreateFromGIF($Image);
$NewImage = ImageCreate($Width, $Height);
}
if ($OrigType == 2) // JPG
{
$OrigImage = ImageCreateFromJPEG($Image);
$NewImage = ImageCreateTrueColor($Width, $Height);
}
if ($OrigType == 3) // PNG
{
$OrigImage = ImageCreateFromPNG($Image);
$NewImage = ImageCreateTrueColor($Width, $Height);
}
// Copy the image to the blank image resized
if (ImageCopyResampled($NewImage,$OrigImage, 0, 0, 0, 0, $Width, $Height, $OrigWidth, $OrigHeight))
{
if ($DestImage)
{
$Image = $DestImage;
}
else
{
@unlink($Image);
}
if ($OrigType == 1) // GIF
{
ImageGIF($NewImage,$Image);
}
if ($OrigType == 2) // JPG
{
ImageJPEG($NewImage,$Image,99);
}
if ($OrigType == 3) // PNG
{
ImagePNG($NewImage,$Image);
}
return true;
}
else
{
return false;
}
}
?>