[eluser]omed habib[/eluser]
I can tell ya this much, I found this code on the Internet and it works perfect. However, I'd still like to figure out the problem with the CI Image class so I can use the watermark features too...
Code:
// function createThumb creates and saves thumbnail image.
// returns boolean $success
// uses older GD library functions if current ones are not available
// parameter string $filePath path to source image
// parameter string $thumbPath path to new thumbnail
function createThumb($filePath, $thumbPath) {
$thumbHeight = 77;
$thumbWidth = 115;
$quality = 200;
// Get the image dimensions.
$dimensions = @getimagesize($filePath);
$width = $dimensions[0];
$height = $dimensions[1];
$smallerSide = min($width, $height);
// Calculate offset of square portion of image
// offsets will both be zero if original image is square
$deltaX = ($width - $smallerSide)/2;
$deltaY = ($height - $smallerSide)/2;
// get image identifier for source image
$imageSrc = @imagecreatefromjpeg($filePath);
// Create an empty thumbnail image.
$imageDest = @imagecreatetruecolor($thumbWidth, $thumbHeight);
$success = @imagecopyresampled(
$imageDest, // Destination image
$imageSrc, // Source image
0, // X coordinate of destination point
0, // Y coordinate of destination point
$deltaX, // X coordinate of source point
$deltaY, // Y coordinate of source point
$thumbWidth, // Destination width
$thumbHeight, // Destination height
$smallerSide, // Source width
$smallerSide // Source height
);
if (!$success) {return false;} {
// save the thumbnail image into a file.
$success = @imagejpeg($imageDest, $thumbPath, $quality);
// Delete both image resources.
@imagedestroy($imageSrc);
@imagedestroy($imageDest);
}
return $success;
}