使用下面的PHP脚本,如果图像是透明的,我将如何添加添加#ffffff
背景颜色的功能,因为我不想要黑色背景。
由于
function uploadImage($inputName, $uploadDir){
$image = $_FILES[$inputName];
$imagePath = '';
// if a file is given
if (trim($image['tmp_name']) != '') {
// get the image extension
$ext = substr(strrchr($image['name'], "."), 1);
// generate a random new file name to avoid name conflict
$imagePath = md5(rand() * time()) . ".$ext";
// check the image width. if it exceed the maximum
// width we must resize it
$size = getimagesize($image['tmp_name']);
if ($size[0] > MAX_WP_LOGO_IMAGE_WIDTH) {
$imagePath = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_WP_LOGO_IMAGE_WIDTH);
} else {
// move the image to category image directory
// if fail set $imagePath to empty string
if (!move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath)) {
$imagePath = '';
}
}
}
return $imagePath;
}
createThumbnail功能
function createThumbnail($srcFile, $destFile, $width, $quality = 75)
{
$thumbnail = '';
if (file_exists($srcFile) && isset($destFile))
{
$size = getimagesize($srcFile);
$w = number_format($width, 0, ',', '');
$h = number_format(($size[1] / $size[0]) * $width, 0, ',', '');
$thumbnail = copyImage($srcFile, $destFile, $w, $h, $quality);
}
// return the thumbnail file name on sucess or blank on fail
return basename($thumbnail);
}