...

View Full Version : JPEG image limit... Re-Written GIF & PNG's? Help!



ukgoped
05-02-2006, 07:43 PM
Well here's my problem... i need to be able to upload every type of image to my website, i use a CMS system and it has a limit at JPG.. i only ever use GIF & PNG's...

Here's the code from my uploading page that detects the image type etc..

If you need any other bits of code please tell me n ill post them up..

Can this be re-written to accept all types of images and thumbnail them etc or is it 'locked' to only do JPEG...

ANY advice would really help me as im getting despirate, as you can see im no scripter and your help is much appreciated!

Thanks in advance,
Chris


if($Submit){

// Check to make sure file is an acceptable jpg
if (eregi ("(.)+\\.(jp(e){0,1}g$)", strtolower($File_name))){

$query = "SELECT * FROM $DB_Projects ORDER BY id DESC LIMIT 0,1";
$result = mysql_query($query, $Link) or queryError("12", mysql_error());
if(mysql_num_rows($result)){
$ROW = mysql_fetch_object($result);
$filename = ($ROW->id + 1) . ".jpg";
}
else $filename = "1.jpg";

if (@copy($File, $admin_location_photo.$filename)){

// size max width or height - 1 to trim mishap edges
$size_thumb = $sxThemeConfig['GalleryMaxDimensionThumb'] - 1;
$size_scaled = $sxThemeConfig['GalleryMaxDimensionProject'] - 1;

$compression_thumb = $sxThemeConfig['GalleryCompressionThumb'];
$compression_scaled = $sxThemeConfig['GalleryCompressionProject'];

if((imageCompatibility() == "truecolor")OR(imageCompatibility() == "normal")){
$image = imagecreatefromjpeg($admin_location_photo.$filename);
$width_original = imagesx($image);
$height_original = imagesy($image);
}
elseif(imageCompatibility() == "imagemagick"){
$image = imagick_readimage($admin_location_photo.$filename);
$width_original = imagick_sample($image, 'width');
$height_original = imagick_sample($image, 'height');
}

$filesize_original = filesize($admin_location_photo.$filename);

// Dimension change needed
if(($width_original > $size_scaled)OR($height_original > $size_scaled)){

$dimensions = resizeDimensions($width_original, $height_original, $size_scaled);

if(imageCompatibility() == "truecolor"){
$image_new = imagecreatetruecolor($dimensions[0]+1, $dimensions[1]+1);
imagecopyresampled($image_new, $image, 0, 0, 0, 0, $dimensions[0]+1, $dimensions[1]+1, $width_original, $height_original);
imagejpeg($image_new, $admin_location_photo_scaled.$filename, $compression_scaled);
imagedestroy($image_new);
}
elseif(imageCompatibility() == "normal"){
$image_new = imagecreate($dimensions[0]+1, $dimensions[1]+1);
imagecopyresized($image_new, $image, 0, 0, 0, 0, $dimensions[0]+1, $dimensions[1]+1, $width_original, $height_original);
imagejpeg($image_new, $admin_location_photo_scaled.$filename, $compression_scaled);
imagedestroy($image_new);
}
elseif(imageCompatibility() == "imagemagick"){
$image_new = imagick_readimage($admin_location_photo.$filename);
imagick_sample($image_new, $dimensions[0]+1, $dimensions[1]+1);
imagick_writeimage($image_new, $admin_location_photo_scaled.$filename);
}

$filesize = filesize($admin_location_photo_scaled.$filename);
$width = $dimensions[0] + 1;
$height = $dimensions[1] + 1;

}else{
@copy($admin_location_photo.$filename, $admin_location_photo_scaled.$filename);
$filesize = filesize($admin_location_photo_scaled.$filename);
$width = $width_original;
$height = $height_original;
}

$dimensions = resizeDimensions($width_original, $height_original, $size_thumb);

if(imageCompatibility() == "truecolor"){
$image_new_thumb = imagecreatetruecolor($dimensions[0]+1, $dimensions[1]+1);
imagecopyresampled($image_new_thumb, $image, 0, 0, 0, 0, $dimensions[0]+1, $dimensions[1]+1, $width_original, $height_original);
imagejpeg($image_new_thumb, $admin_location_thumbnail.$filename, $compression_thumb);
imagedestroy($image_new_thumb);
}
elseif(imageCompatibility() == "normal"){
$image_new_thumb = imagecreate($dimensions[0]+1, $dimensions[1]+1);
imagecopyresized($image_new_thumb, $image, 0, 0, 0, 0, $dimensions[0]+1, $dimensions[1]+1, $width_original, $height_original);
imagejpeg($image_new_thumb, $admin_location_thumbnail.$filename, $compression_thumb);
imagedestroy($image_new_thumb);
}
elseif(imageCompatibility() == "imagemagick"){
$image_new_thumb = imagick_readimage($admin_location_photo.$filename);
imagick_sample($image_new_thumb, $dimensions[0]+1, $dimensions[1]+1);
imagick_writeimage($image_new_thumb, $admin_location_thumbnail.$filename);
}

if($sxSetup['AdvancedProjectMode']){
$width_final = $width_original;
$height_final = $height_original;
$filesize_final = $filesize_original;
$original = 1;
}else{
@unlink($admin_location_photo.$filename);
$width_final = $width;
$height_final = $height;
$filesize_final = $filesize;
$orignial = 0;
}

firepages
05-02-2006, 11:28 PM
might be easier to just convert the uploaded file to a jpeg before you pass it to your function ... if you have imagemagick installed

<?exec("convert $uploaded_filename newfile.jpg");?>

ukgoped
05-03-2006, 09:25 AM
Sounds like a good idea to me... as i said im no scripter so can you insert that into my existing code please?

Thanks alot,
Chris



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum