[英]Image Resize returns a black background
PHP Image resize returns only black background. PHP图像调整大小仅返回黑色背景。
I read all similar posts here, but none of them fixed my problem. 我在这里阅读了所有类似的帖子,但是都没有解决我的问题。
Here is the code: 这是代码:
$namef = $_FILES['image']['name'];
$tmp_name = $_FILES['image']['tmp_name'];
$src = imagecreatefromjpeg($tmp_name);
$location = "../userpictures/standard/".$mdid.".".$mzad;
move_uploaded_file($tmp_name, $location);
list($width, $height, $type, $att) = getimagesize($location);
$newwidth = 200;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,
$width,$height);
$locations = "../userpictures/medium/".$mdid.".".$mzad;
imagejpeg($tmp,$locations,100);
move_uploaded_file($tmp_name, $location);
I've checked whether this code was valid on php tutorials and it was ok with the code. 我已经检查了此代码在php教程上是否有效,并且可以使用该代码。
You create your images with imagecreatetruecolor, which create a new image of W x H filled in black. 您可以使用imagecreatetruecolor创建图像,这将创建一个新的W x H图像(黑色填充)。
See http://php.net/manual/en/function.imagecreatetruecolor.php : 参见http://php.net/manual/en/function.imagecreatetruecolor.php :
imagecreatetruecolor() returns an image identifier representing a black image of the specified size.
imagecreatetruecolor()返回表示指定大小的黑色图像的图像标识符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.