- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我使用 PHP 和 GD 库制作缩略图,但我的代码将 png 透明度变成了纯黑色,有没有改进我的代码的解决方案?
这是我的 php 缩略图制作代码:
function cropImage($nw, $nh, $source, $stype, $dest) {
$size = getimagesize($source);
$w = $size[0];
$h = $size[1];
switch($stype) {
case 'gif':
$simg = imagecreatefromgif($source);
break;
case 'jpg':
$simg = imagecreatefromjpeg($source);
break;
case 'png':
$simg = imagecreatefrompng($source);
break;
}
$dimg = imagecreatetruecolor($nw, $nh);
$wm = $w/$nw;
$hm = $h/$nh;
$h_height = $nh/2;
$w_height = $nw/2;
if($w> $h) {
$adjusted_width = $w / $hm;
$half_width = $adjusted_width / 2;
$int_width = $half_width - $w_height;
imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
} elseif(($w <$h) || ($w == $h)) {
$adjusted_height = $h / $wm;
$half_height = $adjusted_height / 2;
$int_height = $half_height - $h_height;
imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
} else {
imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h);
}
imagejpeg($dimg,$dest,100);
}
谢谢
最佳答案
在 imagecreatetruecolor() 之后:
<?php
// ... Before imagecreatetruecolor()
$dimg = imagecreatetruecolor($width_new, $height_new); // png ?: gif
// start changes
switch ($stype) {
case 'gif':
case 'png':
// integer representation of the color black (rgb: 0,0,0)
$background = imagecolorallocate($dimg , 0, 0, 0);
// removing the black from the placeholder
imagecolortransparent($dimg, $background);
// turning off alpha blending (to ensure alpha channel information
// is preserved, rather than removed (blending with the rest of the
// image in the form of black))
imagealphablending($dimg, false);
// turning on alpha channel information saving (to ensure the full range
// of transparency is preserved)
imagesavealpha($dimg, true);
break;
default:
break;
}
// end changes
$wm = $w/$nw;
$hm = $h/$nh;
// ...
关于php - imagecreatefrompng() 制作黑色背景而不是透明背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2611852/
我正在使用 imagecreatefrompng 简单加载图像。 图像的背景是#E5DDBB。使用下面的代码,它会渲染图像,但背景现在是#DED6AD。 http://www.letslogic.co
我有一个在 Macromedia (Adobe) Fireworks 中创建的图像。我将它导出为带有透明背景的 PNG32。正常调用图片到浏览器就可以了: 但是,当我使用 php 显示图像时,出现了
我已经用 mime 类型检查了文件。如果它是 jpg 或 gif,它可以与 完美配合 $src = imagecreatefromjpeg($tmpName); 和 $src = imagecreat
我正在使用 PHP 创建一张海报,我想在海报上添加数字。 我使用下面的代码来添加它们: $src1 = imagecreatefrompng("m2.png"); $widthsrc=0; $heig
我使用 PHP 和 GD 库制作缩略图,但我的代码将 png 透明度变成了纯黑色,有没有改进我的代码的解决方案? 这是我的 php 缩略图制作代码: function cropImage($nw, $
在我的一个 PHP 项目中,imagecreatefrompng 提示图像“不是有效的 PNG 文件”。 Warning: imagecreatefrompng() [function.imagecr
在我的脚本中,我有以下几行: $test = @imagecreatefrompng($name); if ($test) { ... } 我确定 $name 表示磁盘上的现有文件,但我必须处理该文件
有没有办法用 this 的 imagecreatefrompng() 创建图像? PHP 中的 base 64 PNG 代码? 最佳答案 这对我有用 关于php - 来自 base64 代码的 im
采用以下基本图像 (PNG-24): 我们正在尝试将文本写入图像,如下所示: 这会产生低质量的文本(非常 block 状)——如何消除文本的锯齿以使其看起来平滑? 这是 block 状版本: 在仔分
这是一个 PNG 文件:http://imgur.com/NUl4v.png (是的,没关系,这是一只带有标志的有趣企鹅......) 运行以下代码时: imagecreatefrompng('htt
当我尝试在不正确的 png 图像上使用 php-gd 函数时,出现致命的 PHP 错误。这似乎是某种错误,因为根据函数文档(例如 imagecreatefrompng): * @return reso
它现在给出: PHP Fatal error: Call to undefined function imagecreatefromjpeg() 但是 gd 库是启用的。 最佳答案 安装 php5-
这是我在 php 错误日志中收到的错误消息。 到目前为止,我知道问题出在 GD 库上,它没有安装(我认为没有安装,但它之前在我的服务器上工作,现在不是,所以我不知道发生了什么,但我想假设未安装)。 我
我是一名优秀的程序员,十分优秀!