English 中文(简体)
图像 GD - 白色背景
原标题:Image GD - White Background
  • 时间:2012-05-24 10:59:59
  •  标签:
  • php
$background = imagecreatetruecolor(709,709);

$whiteBackground = imagecolorallocate($background, 255, 255, 255);

imagecopyresampled($whiteBackground, $new_img,(709-$imageWidth)/2,(709-$imageHeight)/2, 0, 0, $imageWidth, $imageHeight, $width, $height);

ImageJpeg ($background,"$path/$newName.$file_ext", 85);

我试图用 GD 创建图像, 带有白色背景 。 但是没有运气, 任何想法会做错什么? 我知道一个图像泵, 如果我拿掉白色背景部分, 所以它与创建图像代码没有错 。

谢谢 谢谢

最佳回答

您丢失了 imagefill () 方法 $background 上的 imagefill () 方法, 配有白色 。

并且可以将图像复制器从[色 复制到[图像],你应该从[图像]复制到[图像]。

$background = imagecreatetruecolor(709,709);
$whiteBackground = imagecolorallocate($background, 255, 255, 255);
imagefill($background,0,0,$whiteBackground);
imagecopyresampled($background, $new_img,(709-$imageWidth)/2,(709-$imageHeight)/2, 0, 0, $imageWidth, $imageHeight, $width, $height);
ImageJpeg ($background,"$path/$newName.$file_ext", 85);
问题回答

希望这工作成功

$background = imagecreatetruecolor(709,709);
$whiteBackground = imagecolorallocate($background, 255, 255, 255);
imagefill($background,0,0,$whiteBackground);
$use_new_img = imagecreatefromjpeg($new_img);
imagecopyresampled($whiteBackground,$use_new_img,(709-$imageWidth)/2,  (709-$imageHeight)/2, 0, 0,$imageWidth,$imageHeight,$width,$height);
ImageJpeg ($background,"$path/$newName.$file_ext", 85);

http://php.net/manual/en/formation.imagecopresampled.php 表示,前两个论点需要 $dst_image $src_image

$new_img 在您的代码中不存在, 需要以 imagecreate trextcolor (); 创建

默认情况下, 它应该是我所相信的白色背景, 所以您不需要 image cololallate ()





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...