Php 创建缩略图并添加背景,使滑块大小为933*335(以避免拉伸图像)

Php 创建缩略图并添加背景,使滑块大小为933*335(以避免拉伸图像),php,image-processing,thumbnails,Php,Image Processing,Thumbnails,/*创建缩略图,我想将图像大小调整为933*335。假设图像是513*335,因为它不是矩形的。如何添加白色或黑色背景,使生成的图像为933*335?这是否可能与我的缩略图指南*/ 函数make_thumb($src,$dest,$desired_height=335,$ext){ } 这是用于创建缩略图的代码,但我想在不拉伸图像的情况下创建933*335 //function for creating an thumbnail private function _generateThu

/*创建缩略图,我想将图像大小调整为933*335。假设图像是513*335,因为它不是矩形的。如何添加白色或黑色背景,使生成的图像为933*335?这是否可能与我的缩略图指南*/ 函数make_thumb($src,$dest,$desired_height=335,$ext){

} 这是用于创建缩略图的代码,但我想在不拉伸图像的情况下创建933*335

//function for creating an thumbnail   
 private function _generateThumb() {
switch($this->imageType) {
        case 'jpg':
            $image = @imagecreatefromjpeg($this->pathToImage);
        break;
        case 'gif':
        $image = @imagecreatefromgif($this->pathToImage);
        break;
        case 'png':
            $image = @imagecreatefrompng($this->pathToImage);
        break;
}

if ($image === false) {
    trigger_error('image could not be created', 1024);
    print 'nöööööö'; exit;
}
$thumbImage = @ImageCreateTrueColor(933, $this->thumbHeight);

//select background color using number between 0 to 255
$color = imagecolorallocate($thumbImage,0,0,0);//black color
imagefill($thumbImage, 0, 0, $color);

if ($this->imageType == 'png' || $this->imageType == 'gif')
{
imagealphablending($thumbImage, false);

$s=933-$this->thumbWidth;
$s=$s/2;//to keep image in center i.e distance from x-axis
ImageCopyResampled($thumbImage, $image,$s,0,0,0, $this->thumbWidth, $this->thumbHeight,$this->imageWidth, $this->imageHeight);

}

@ShaPesar:如何使用PHP创建白色背景的缩略图?
//function for creating an thumbnail   
 private function _generateThumb() {
switch($this->imageType) {
        case 'jpg':
            $image = @imagecreatefromjpeg($this->pathToImage);
        break;
        case 'gif':
        $image = @imagecreatefromgif($this->pathToImage);
        break;
        case 'png':
            $image = @imagecreatefrompng($this->pathToImage);
        break;
}

if ($image === false) {
    trigger_error('image could not be created', 1024);
    print 'nöööööö'; exit;
}
$thumbImage = @ImageCreateTrueColor(933, $this->thumbHeight);

//select background color using number between 0 to 255
$color = imagecolorallocate($thumbImage,0,0,0);//black color
imagefill($thumbImage, 0, 0, $color);

if ($this->imageType == 'png' || $this->imageType == 'gif')
{
imagealphablending($thumbImage, false);

$s=933-$this->thumbWidth;
$s=$s/2;//to keep image in center i.e distance from x-axis
ImageCopyResampled($thumbImage, $image,$s,0,0,0, $this->thumbWidth, $this->thumbHeight,$this->imageWidth, $this->imageHeight);