php – 使用alpha颜色的imagerotate不起作用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 使用alpha颜色的imagerotate不起作用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2112字,纯文字阅读大概需要4分钟。
内容图文
![php – 使用alpha颜色的imagerotate不起作用](/upload/InfoBanner/zyjiaocheng/794/88be5c79e6b34211a5cc653e13baa1fd.jpg)
我有一个奇怪的情况.
它看起来像背景并不总是透明的,但在某种程度上它打破了……
这是代码:
$angle = !empty($_GET['a']) ? (int)$_GET['a'] : 0;
$im = imagecreatefromgif(__DIR__ . '/track/direction1.gif');
imagealphablending($im, false);
imagesavealpha($im, true);
$transparency = imagecolorallocatealpha($im, 0, 0, 0, 127);
$rotated = imagerotate($im, $angle, $transparency);
imagealphablending($rotated, false);
imagesavealpha($rotated, true);
imagepng($rotated);
imagedestroy($rotated);
imagedestroy($im);
header('Content-Type: image/png');
只是不明白发生了什么…我错过了什么?
EDIT1
添加了func:
if(!function_exists('imagepalettetotruecolor'))
{
function imagepalettetotruecolor(&$src)
{
if(imageistruecolor($src))
{
return true;
}
$dst = imagecreatetruecolor(imagesx($src), imagesy($src));
$black = imagecolorallocate($dst, 0, 0, 0);
imagecolortransparent($dst, $black);
$black = imagecolorallocate($src, 0, 0, 0);
imagecolortransparent($src, $black);
imagecopy($dst, $src, 0, 0, 0, 0, imagesx($src), imagesy($src));
imagedestroy($src);
$src = $dst;
return true;
}
}
但现在坚持这个广场不想透明….
解决方法:
imagerotate执行不力;我经常注意到错误/削减边缘.如果必须,您可以使用24位透明PNG图像而不是透明GIF(PNG支持Alpha透明度,这意味着边缘将与HTML背景颜色很好地融合).
该功能有透明度问题,解决方法是添加两行:
<?php
$angle = (int) $_GET['a'];
$source = imagecreatefrompng(__DIR__ . DIRECTORY_SEPARATOR . 'direction1.png');
$rotation = imagerotate($source, $angle, imageColorAllocateAlpha($source, 0, 0, 0, 127));
imagealphablending($rotation, false); // handle issue when rotating certain angles
imagesavealpha($rotation, true); // handle issue when rotating certain angles
header('Content-type: image/png');
imagepng($rotation);
imagedestroy($source);
imagedestroy($rotation);
结果:
作为替代,我可以建议CSS transform吗?
img:nth-child(2) {
transform: rotate(45deg);
}
img:nth-child(3) {
transform: rotate(90deg);
}
img:nth-child(4) {
transform: rotate(135deg);
}
<img src="http://i.stack.imgur.com/oZlZ9.png">
<img src="http://i.stack.imgur.com/oZlZ9.png">
<img src="http://i.stack.imgur.com/oZlZ9.png">
<img src="http://i.stack.imgur.com/oZlZ9.png">
内容总结
以上是互联网集市为您收集整理的php – 使用alpha颜色的imagerotate不起作用全部内容,希望文章能够帮你解决php – 使用alpha颜色的imagerotate不起作用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。