Create thumbnail after upload, PHP - php

I have implemented a file upload for pictures on my page, and tried to somehow generate thumbnails with the intention of clicking them to view via fancybox. The upload works but my function to create a thumbnail doesn't.
(This is included in my upload.php, right after "move_uploaded_file":
<?php
$src = $subdir.$fileupload['name'];
function make_thumb($src)
{
$source_image = imagecreatefromjpeg($src); //For testing purposes only jpeg now
$width = imagesx($source_image);
$height = imagesy($source_image);
$desired_width = 220;
$desired_height = floor($height * ($desired_width / $width));
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
header("Content-type: image/jpeg");
imagejpeg($virtual_image, realpath('./Thumbnails/filename.jpg')); //Temporary filename, will be changed
}
?>
Just FYI, this is an assignment and since I am a php beginner, I did use google, but can't find the problem in my case. Maybe my understanding of php is lacking too much.

Use this img_resize function, it is good for the most popular image formats
function img_resize($src, $dest, $width, $height, $rgb = 0xFFFFFF, $quality = 100)
{
if (!file_exists($src))
return false;
$size = getimagesize($src);
if ($size === false)
return false;
$format = strtolower(substr($size['mime'], strpos($size['mime'], '/') + 1));
$icfunc = "imagecreatefrom" . $format;
if (!function_exists($icfunc))
return false;
$x_ratio = $width / $size[0];
$y_ratio = $height / $size[1];
$ratio = min($x_ratio, $y_ratio);
$use_x_ratio = ($x_ratio == $ratio);
$new_width = $use_x_ratio ? $width : floor($size[0] * $ratio);
$new_height = !$use_x_ratio ? $height : floor($size[1] * $ratio);
$new_left = $use_x_ratio ? 0 : floor(($width - $new_width) / 2);
$new_top = !$use_x_ratio ? 0 : floor(($height - $new_height) / 2);
$isrc = $icfunc($src);
$idest = imagecreatetruecolor($width, $height);
imagefill($idest, 0, 0, $rgb);
if (($format == 'gif') or ($format == 'png')) {
imagealphablending($idest, false);
imagesavealpha($idest, true);
}
if ($format == 'gif') {
$transparent = imagecolorallocatealpha($idest, 255, 255, 255, 127);
imagefilledrectangle($idest, 0, 0, $width, $height, $transparent);
imagecolortransparent($idest, $transparent);
}
imagecopyresampled($idest, $isrc, $new_left, $new_top, 0, 0, $new_width, $new_height, $size[0], $size[1]);
getResultImage($idest, $dest, $size['mime']);
imagedestroy($isrc);
imagedestroy($idest);
return true;
}
function getResultImage($dst_r, $dest_path, $type)
{
switch ($type) {
case 'image/jpg':
case 'image/jpeg':
case 'image/pjpeg':
return imagejpeg($dst_r, $dest_path, 90);
break;
case 'image/png';
return imagepng($dst_r, $dest_path, 2);
break;
case 'image/gif';
return imagegif($dst_r, $dest_path);
break;
default:
return;
}
}

Related

PHP - How can I copy the image as transparent png

First, I'm not master of PHP. I'm using a function for resize and crop images. It's working perfectly until I upload a transparent png. :)
It saves the png with black background. I found some answers on stackoverflow but I can't combine it with my codes.
Here is my function:
//resize and crop image
function resize_crop_image($max_width, $max_height, $source_file, $dst_dir, $quality = 90){
$imgsize = getimagesize($source_file);
$width = $imgsize[0];
$height = $imgsize[1];
$mime = $imgsize['mime'];
switch($mime){
case 'image/gif':
$image_create = "imagecreatefromgif";
$image = "imagegif";
$format = "gif";
break;
case 'image/png':
$image_create = "imagecreatefrompng";
$image = "imagepng";
$quality = 7;
$format = "png";
break;
case 'image/jpeg':
$image_create = "imagecreatefromjpeg";
$image = "imagejpeg";
$format = "jpg";
break;
default:
return false;
break;
}
$dst_img = imagecreatetruecolor($max_width, $max_height);
$src_img = $image_create($source_file);
$width_new = $height * $max_width / $max_height;
$height_new = $width * $max_height / $max_width;
//if the new width is greater than the actual width of the image, then the height is too large and the rest cut off, or vice versa
if($width_new > $width){
//cut point by height
$h_point = (($height - $height_new) / 2);
//copy image
imagecopyresampled($dst_img, $src_img, 0, 0, 0, $h_point, $max_width, $max_height, $width, $height_new);
}else{
//cut point by width
$w_point = (($width - $width_new) / 2);
imagecopyresampled($dst_img, $src_img, 0, 0, $w_point, 0, $max_width, $max_height, $width_new, $height);
}
// you can ignore these 4 lines. I'm using it for change the name.
$nameforimage = rand('11111111', '9999999999');
$nameforimage2 = rand('11111111', '9999999999');
$newname = $nameforimage."_".$nameforimage2;
$newdir = $dst_dir."".$newname.".".$format;
$image($dst_img, $newdir, $quality);
if($dst_img)imagedestroy($dst_img);
if($src_img)imagedestroy($src_img);
return $newname.".".$format;
}
EDIT:
Okay I've found a solution.
Just add these lines:
imagealphablending($dst_img, false);
imagesavealpha($dst_img, true);
$transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127);
imagefilledrectangle($dst_img, 0, 0, $max_width, $max_height, $transparent);
After this line:
$dst_img = imagecreatetruecolor($max_width, $max_height);
You have to enable saving the alpha channel.
It can be done with imagesavealpha(), e.g.:
// As per the manual, alpha blending must be disabled
imagealphablending($dst_img, false);
imagesavealpha($dst_img, true);

imagecreatefromjpeg shows a blank image

I am using the following code in html to call a php file to create a thumbnail and show it on this page
&w=150&h=&00" alt="Image" />
the code of miniature.php is the following :
<?php
function redimensionner_image($chemin_image, $largeur_max, $hauteur_max)
{
list($src_w, $src_h) = getimagesize($chemin_image);
$dst_w = $largeur_max;
$dst_h = $hauteur_max;
if($src_w < $dst_w)
$dst_w = $src_w;
// Teste les dimensions tenant dans la zone
$test_h = round(($dst_w / $src_w) * $src_h);
$test_w = round(($dst_h / $src_h) * $src_w);
if(!$dst_h)// Si Height final non précisé (0)
$dst_h = $test_h;
elseif(!$dst_w) // Sinon si Width final non précisé (0)
$dst_w = $test_w;
elseif($test_h>$dst_h) // Sinon teste quel redimensionnement tient dans la zone
$dst_w = $test_w;
else
$dst_h = $test_h;
$array_ext = explode('.', $chemin_image);
$extension = strtolower($array_ext[count($array_ext)-1]);
if($extension == 'jpg' || $extension == 'jpeg')
$img_in = imagecreatefromjpeg($chemin_image);
else if($extension == 'png')
$img_in = imagecreatefrompng($chemin_image);
else if($extension == 'gif')
$img_in = imagecreatefromgif($chemin_image);
else
return false;
$img_out = imagecreatetruecolor($dst_w, $dst_h);
imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, $dst_w, $dst_h, imagesx($img_in), imagesy($img_in));
imagejpeg($img_out);
}
?>
However, Imagecreatefromjpeg returns a black image after resize. Any help please
First you don't need to explode the file-extension as getimagesize will give you the type:
list($width, $height, $type) = getimagesize($source);
Next I don't follow your size calculations, try to simplify them, f.e.:
$scale = min($maxWidth / $width, $maxHeight / $height, 1); // We only use downsampling, no upsampling! If you need upsampling remove the '1' parameter
$newWidth = min($width * $scale, $maxWidth);
$newHeight = min($height * $scale, $maxHeight);
Simple rescaling and preserves aspect ratio.
For reference, here is the code I use in my projects:
function SaveImageAsJpeg($sourceFilename, $destFilename, $maxWidth = 0, $maxHeight = 0, $jpegQuality = 80) {
list($width, $height, $type) = getimagesize($sourceFilename);
$sourceImage = false;
switch ($type) {
case IMAGETYPE_GIF:
$sourceImage = imagecreatefromgif($sourceFilename);
break;
case IMAGETYPE_JPEG:
$sourceImage = imagecreatefromjpeg($sourceFilename);
break;
case IMAGETYPE_PNG:
$sourceImage = imagecreatefrompng($sourceFilename);
break;
}
if (!$sourceImage)
return false;
if (($maxWidth == 0) || ($maxHeight == 0)) {
// Don't resize
$destinationImage = imagecreatetruecolor($width, $height);
imagecopy($destinationImage, $sourceImage, 0, 0, 0, 0, $width, $height);
imagejpeg($destinationImage, $destFilename, $jpegQuality);
imagedestroy($destinationImage);
} else {
// Resize image
$scale = min($maxWidth / $width, $maxHeight / $height, 1); // We only use downsampling, no upsampling! If you need upsampling remove the '1' parameter
$newWidth = min($width * $scale, $maxWidth);
$newHeight = min($height * $scale, $maxHeight);
$destinationImage = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($destinationImage, $sourceImage, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imagejpeg($destinationImage, $destFilename, $jpegQuality);
imagedestroy($destinationImage);
}
imagedestroy($sourceImage);
return true;
}
Of course, above code will not return image data. It just saves the rescaled image to an other file on the server. But if you pass NULL as $destFilename parameter, it will output the image data to the output stream:
header('Content-Type: image/jpeg');
SaveImageAsJpeg($sourceFilename, NULL, 200, 200);
If you're still getting a black image, I would suggest increasing the PHP memory limit. If you can modify PHP.INI, adjust the memory_limit setting. Otherwise use a .htaccess file with this line, f.e.: php_value memory_limit 64M.

Crop from the center and resize in PHP (function)

I want to have a function that resizes to a specific height en weight of an image without losing the aspect ratio. So first i want to crop it and then resizing it.
This is what i got so far:
function image_resize($src, $dst, $width, $height, $crop=1){
if(!list($w, $h) = getimagesize($src)) return "Unsupported picture type!";
$type = strtolower(substr(strrchr($src,"."),1));
if($type == 'jpeg') $type = 'jpg';
switch($type){
case 'bmp': $img = imagecreatefromwbmp($src); break;
case 'gif': $img = imagecreatefromgif($src); break;
case 'jpg': $img = imagecreatefromjpeg($src); break;
case 'png': $img = imagecreatefrompng($src); break;
default : return "Unsupported picture type!";
}
// resize
$originalW = $w;
$originalH = $h;
if($crop){
if($w < $width or $h < $height) return "Picture is too small!";
$ratio = max($width/$w, $height/$h);
$h = $height / $ratio;
$x = ($w - $width / $ratio) / 2;
$w = $width / $ratio;
}
else{
if($w < $width and $h < $height) return "Picture is too small!";
$ratio = min($width/$w, $height/$h);
$width = $w * $ratio;
$height = $h * $ratio;
$x = 0;
}
$new = imagecreatetruecolor($width, $height);
// preserve transparency
if($type == "gif" or $type == "png"){
imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127));
imagealphablending($new, false);
imagesavealpha($new, true);
}
imagecopyresampled($new, $img, 0, 0, ($originalW - $width)/2, ($originalH - $height)/2, $width, $height, $w, $h);
switch($type){
case 'bmp': imagewbmp($new, $dst); break;
case 'gif': imagegif($new, $dst); break;
case 'jpg': imagejpeg($new, $dst); break;
case 'png': imagepng($new, $dst); break;
}
return true;
}
The function is working fine. But i still have a problem. For example: When i resize a portrait image thats (300 × 450) to (260 x 140) i get a black side bar which i dont want.
Here are the 2 images:
It worked for me. You can try:
$x=288; $y=202; // my final thumb
$ratio_thumb=$x/$y; // ratio thumb
list($xx, $yy) = getimagesize($image); // original size
$ratio_original=$xx/$yy; // ratio original
if ($ratio_original>=$ratio_thumb) {
$yo=$yy;
$xo=ceil(($yo*$x)/$y);
$xo_ini=ceil(($xx-$xo)/2);
$xy_ini=0;
} else {
$xo=$xx;
$yo=ceil(($xo*$y)/$x);
$xy_ini=ceil(($yy-$yo)/2);
$xo_ini=0;
}
imagecopyresampled($thumb, $source, 0, 0, $xo_ini, $xy_ini, $x, $y, $xo, $yo);
works fine with:
imagecopyresampled($new, $img, 0, 0, 0, 0, $width, $height, $w, $h);

Upload, resize, and crop center of image with PHP

I'm wanting to create a very very basic upload, resize, and crop PHP script.
The functionality to this will be identical (last i checked anyway) to the method Twitter uses to upload avatar pictures.
I want the script to take any size image, resize the shortest side to 116px, then crop off the top and bottom (or left and right side if it's landscape) as to get a square 116px by 116px.
I don't want a bloated PHP script with client side resizing or anything, just a simple PHP resize and crop. How is this done?
The GD Library is a good place to start.
http://www.php.net/manual/en/book.image.php
There a simple to use, open source library called PHP Image Magician. It uses GD but simplifies it's usage to 3 lines.
Example of basis usage:
$magicianObj = new imageLib('racecar.jpg');
$magicianObj -> resizeImage(100, 200, 'crop');
$magicianObj -> saveImage('racecar_small.png');
If you want an example to work from my upload, resize and crop class does all of this plus some other cool stuff - you can use it all if needed or just take the bits out that you like:
http://www.mjdigital.co.uk/blog/php-upload-and-resize-image-class/
I don't think it is too bloated! - you can just do something this (not tested):
if((isset($_FILES['file']['error']))&&($_FILES['file']['error']==0)){ // if a file has been posted then upload it
include('INCLUDE_CLASS_FILE_HERE.php');
$myImage = new _image;
// upload image
$myImage->uploadTo = 'uploads/'; // SET UPLOAD FOLDER HERE
$myImage->returnType = 'array'; // RETURN ARRAY OF IMAGE DETAILS
$img = $myImage->upload($_FILES['file']);
if($img) {
$myImage->newWidth = 116;
$myImage->newHeight = 116;
$i = $myImage->resize(); // resizes to 116px keeping aspect ratio
// get new image height
$imgWidth = $i['width'];
// get new image width
$imgHeight = $i['height'];
if($i) {
// work out where to crop it
$cropX = ($imgWidth>116) ? (($imgWidth-116)/2) : 0;
$cropY = ($imgHeight>116) ? (($imgHeight-116)/2) : 0;
$cropped = $myImage->crop(116,116,$cropX,$cropY);
if($cropped) { echo 'It Worked (I think!)'; print_r($cropped);
} else { echo 'Crop failed'; }
} else { echo 'Resize failed'; }
} else { echo 'Upload failed'; }
I made this simple function which is very easy to use, it allows you to resize, crop and center an image to a specific width and height, it can suppert JPGs, PNGs and GIFs. Feel free to copy and paste it to your code:
function resize_imagejpg($file, $w, $h, $finaldst) {
list($width, $height) = getimagesize($file);
$src = imagecreatefromjpeg($file);
$ir = $width/$height;
$fir = $w/$h;
if($ir >= $fir){
$newheight = $h;
$newwidth = $w * ($width / $height);
}
else {
$newheight = $w / ($width/$height);
$newwidth = $w;
}
$xcor = 0 - ($newwidth - $w) / 2;
$ycor = 0 - ($newheight - $h) / 2;
$dst = imagecreatetruecolor($w, $h);
imagecopyresampled($dst, $src, $xcor, $ycor, 0, 0, $newwidth, $newheight,
$width, $height);
imagejpeg($dst, $finaldst);
imagedestroy($dst);
return $file;
}
function resize_imagegif($file, $w, $h, $finaldst) {
list($width, $height) = getimagesize($file);
$src = imagecreatefromgif($file);
$ir = $width/$height;
$fir = $w/$h;
if($ir >= $fir){
$newheight = $h;
$newwidth = $w * ($width / $height);
}
else {
$newheight = $w / ($width/$height);
$newwidth = $w;
}
$xcor = 0 - ($newwidth - $w) / 2;
$ycor = 0 - ($newheight - $h) / 2;
$dst = imagecreatetruecolor($w, $h);
$background = imagecolorallocatealpha($dst, 0, 0, 0, 127);
imagecolortransparent($dst, $background);
imagealphablending($dst, false);
imagesavealpha($dst, true);
imagecopyresampled($dst, $src, $xcor, $ycor, 0, 0, $newwidth, $newheight,
$width, $height);
imagegif($dst, $finaldst);
imagedestroy($dst);
return $file;
}
function resize_imagepng($file, $w, $h, $finaldst) {
list($width, $height) = getimagesize($file);
$src = imagecreatefrompng($file);
$ir = $width/$height;
$fir = $w/$h;
if($ir >= $fir){
$newheight = $h;
$newwidth = $w * ($width / $height);
}
else {
$newheight = $w / ($width/$height);
$newwidth = $w;
}
$xcor = 0 - ($newwidth - $w) / 2;
$ycor = 0 - ($newheight - $h) / 2;
$dst = imagecreatetruecolor($w, $h);
$background = imagecolorallocate($dst, 0, 0, 0);
imagecolortransparent($dst, $background);
imagealphablending($dst, false);
imagesavealpha($dst, true);
imagecopyresampled($dst, $src, $xcor, $ycor, 0, 0, $newwidth,
$newheight,$width, $height);
imagepng($dst, $finaldst);
imagedestroy($dst);
return $file;
}
function ImageResize($file, $w, $h, $finaldst) {
$getsize = getimagesize($file);
$image_type = $getsize[2];
if( $image_type == IMAGETYPE_JPEG) {
resize_imagejpg($file, $w, $h, $finaldst);
} elseif( $image_type == IMAGETYPE_GIF ) {
resize_imagegif($file, $w, $h, $finaldst);
} elseif( $image_type == IMAGETYPE_PNG ) {
resize_imagepng($file, $w, $h, $finaldst);
}
}
All you have to do to use it is call it like so:
ImageResize(image, width, height, destination);
E.g.
ImageResize("uploads/face.png", 100, 150, "images/user332profilepic.png");

How do I fill white background while resize image

Current background is black. How to change the color to be white?
#assuming the mime type is correct
switch ($imgtype) {
case 'image/jpeg':
$source = imagecreatefromjpeg($source_image);
break;
case 'image/gif':
$source = imagecreatefromgif($source_image);
break;
case 'image/png':
$source = imagecreatefrompng($source_image);
break;
default:
die('Invalid image type.');
}
#Figure out the dimensions of the image and the dimensions of the desired thumbnail
$src_w = imagesx($source);
$src_h = imagesy($source);
#Do some math to figure out which way we'll need to crop the image
#to get it proportional to the new size, then crop or adjust as needed
$width = $info[0];
$height = $info[1];
$x_ratio = $tn_w / $src_w;
$y_ratio = $tn_h / $src_h;
if (($x_ratio * $height) < $tn_w) {
$new_h = ceil($x_ratio * $height);
$new_w = $tn_w;
} else {
$new_w = ceil($y_ratio * $width);
$new_h = $tn_h;
}
$x_mid = $new_w / 2;
$y_mid = $new_h / 2;
$newpic = imagecreatetruecolor(round($new_w), round($new_h));
imagecopyresampled($newpic, $source, 0, 0, 0, 0, $new_w, $new_h, $src_w, $src_h);
$final = imagecreatetruecolor($tn_w, $tn_h);
imagecopyresampled($final, $newpic, 0, 0, ($x_mid - ($tn_w / 2)), ($y_mid - ($tn_h / 2)), $tn_w, $tn_h, $tn_w, $tn_h);
#if we need to add a watermark
if ($wmsource) {
#find out what type of image the watermark is
$info = getimagesize($wmsource);
$imgtype = image_type_to_mime_type($info[2]);
#assuming the mime type is correct
switch ($imgtype) {
case 'image/jpeg':
$watermark = imagecreatefromjpeg($wmsource);
break;
case 'image/gif':
$watermark = imagecreatefromgif($wmsource);
break;
case 'image/png':
$watermark = imagecreatefrompng($wmsource);
break;
default:
die('Invalid watermark type.');
}
#if we're adding a watermark, figure out the size of the watermark
#and then place the watermark image on the bottom right of the image
$wm_w = imagesx($watermark);
$wm_h = imagesy($watermark);
imagecopy($final, $watermark, $tn_w - $wm_w, $tn_h - $wm_h, 0, 0, $tn_w, $tn_h);
}
if (imagejpeg($final, $destination, $quality)) {
return true;
}
return false;
}
Black & White
$final = imagecreatetruecolor($tn_w, $tn_h);
$backgroundColor = imagecolorallocate($final, 255, 255, 255);
imagefill($final, 0, 0, $backgroundColor);
//imagecopyresampled($final, $newpic, 0, 0, ($x_mid - ($tn_w / 2)), ($y_mid - ($tn_h / 2)), $tn_w, $tn_h, $tn_w, $tn_h);
imagecopy($final, $newpic, (($tn_w - $new_w)/ 2), (($tn_h - $new_h) / 2), 0, 0, $new_w, $new_h);
Here is your whole script (tested with portrait, landscape and square jpg):
<?php
function resize($source_image, $destination, $tn_w, $tn_h, $quality = 100, $wmsource = false)
{
$info = getimagesize($source_image);
$imgtype = image_type_to_mime_type($info[2]);
#assuming the mime type is correct
switch ($imgtype) {
case 'image/jpeg':
$source = imagecreatefromjpeg($source_image);
break;
case 'image/gif':
$source = imagecreatefromgif($source_image);
break;
case 'image/png':
$source = imagecreatefrompng($source_image);
break;
default:
die('Invalid image type.');
}
#Figure out the dimensions of the image and the dimensions of the desired thumbnail
$src_w = imagesx($source);
$src_h = imagesy($source);
#Do some math to figure out which way we'll need to crop the image
#to get it proportional to the new size, then crop or adjust as needed
$x_ratio = $tn_w / $src_w;
$y_ratio = $tn_h / $src_h;
if (($src_w <= $tn_w) && ($src_h <= $tn_h)) {
$new_w = $src_w;
$new_h = $src_h;
} elseif (($x_ratio * $src_h) < $tn_h) {
$new_h = ceil($x_ratio * $src_h);
$new_w = $tn_w;
} else {
$new_w = ceil($y_ratio * $src_w);
$new_h = $tn_h;
}
$newpic = imagecreatetruecolor(round($new_w), round($new_h));
imagecopyresampled($newpic, $source, 0, 0, 0, 0, $new_w, $new_h, $src_w, $src_h);
$final = imagecreatetruecolor($tn_w, $tn_h);
$backgroundColor = imagecolorallocate($final, 255, 255, 255);
imagefill($final, 0, 0, $backgroundColor);
//imagecopyresampled($final, $newpic, 0, 0, ($x_mid - ($tn_w / 2)), ($y_mid - ($tn_h / 2)), $tn_w, $tn_h, $tn_w, $tn_h);
imagecopy($final, $newpic, (($tn_w - $new_w)/ 2), (($tn_h - $new_h) / 2), 0, 0, $new_w, $new_h);
#if we need to add a watermark
if ($wmsource) {
#find out what type of image the watermark is
$info = getimagesize($wmsource);
$imgtype = image_type_to_mime_type($info[2]);
#assuming the mime type is correct
switch ($imgtype) {
case 'image/jpeg':
$watermark = imagecreatefromjpeg($wmsource);
break;
case 'image/gif':
$watermark = imagecreatefromgif($wmsource);
break;
case 'image/png':
$watermark = imagecreatefrompng($wmsource);
break;
default:
die('Invalid watermark type.');
}
#if we're adding a watermark, figure out the size of the watermark
#and then place the watermark image on the bottom right of the image
$wm_w = imagesx($watermark);
$wm_h = imagesy($watermark);
imagecopy($final, $watermark, $tn_w - $wm_w, $tn_h - $wm_h, 0, 0, $tn_w, $tn_h);
}
if (imagejpeg($final, $destination, $quality)) {
return true;
}
return false;
}
resize('teszt2.jpg', 'out.jpg', 100, 100);
?>
<img src="out.jpg">
This is working for me. Although it logically seems like it should fill the whole image with the $bgcolor, it only fills the parts that are "behind" the resampled image.
imagecopyresampled($resized_image, $original_image, $xoffset, $yoffset, 0, 0, $new_width, $new_height, $orig_width, $orig_height);
$bgcolor = imagecolorallocate($resized_image, $red, $green, $blue);
imagefill($resized_image, 0, 0, $bgcolor);

Categories