When a image is uploaded it creates a thumbnail image, right now it only workes with jpeg, couldent finda funktion that converts other file types like bmp, tif, gif, png to a jpg? How can it be done? here is the script. function resize($imgH, $sizeX, $sizeY) { $imgR = imagecreatetruecolor($sizeX, $sizeY); imageCopyResized($imgR, $imgH, 0, 0, 0, 0, imageSX($imgR), imageSY($imgR), imageSX($imgH), imageSY($imgH)); return $imgR; } $filename_thumb = $new_file_name; $output = 'thumbnails/'.$filename_thumb; $width_orginal = $width; //Width of the orginal image $height_orginal = $height; // Height of the orginal image if($width_orginal > $height_orginal) { $biggest_side = $width_orginal; $smallest_side = $height_orginal; } else { $biggest_side = $height_orginal; $smallest_side = $width_orginal; } $aspect_ratio = ($biggest_side)/($smallest_side); $short_side = (floor(150/($aspect_ratio))); if ($short_side == 0) $short_side = 1; if($width_orginal > $height_orginal) { $new_width = 150; $new_height = $short_side; } else { $new_height = 150; $new_width = $short_side; } $imgH = imageCreateFromJpeg('uploads/'.$filename_thumb); imageJpeg(resize($imgH, $new_width, $new_height), $output, 100); PHP:
my gallery2 software uses ImageMagick to do such jobs. I also use ImageMagick offline on my linux machine to do such jobs very efficiently. From man ImageMagick: ImageMagick suite of tools. Use it to convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more. normally on most hosts ImageMagick might be preinstalled or it can be installed by you into your user-space. it's an ideal tool on Linux machines to batch process masses of pics in various formats efficiently. for more detals about PHP code - you may have a look at the code-modules of gallery2 - it's all open source
To jpg images you are using the functions: imageCreateFromJpeg() and imageJpeg() To use other formats, try to detect file extension or myme type of the file and then use functions like: imagecreatefromgif() imagecreatefrompng() info+documentation: php.net etc...