php gd imagerotate fails when -1 is passed for $bgd_color

倖福魔咒の 提交于 2021-02-05 06:11:10

问题


I had this problem on a client server

$tmp = imagerotate($tmp, $angle, -1);

$tmp => bool(false) with no error message displayed

$tmp = imagerotate($tmp, $angle, imagecolorallocatealpha($tmp, 0, 0, 0 , 127));

this works fine
$tmp => resource(89) of type (gd)

What server configuration variable should be changed to make -1 work ?

GD Version: bundled (2.1.0 compatible)
libPNG Version: 1.2.44

回答1:


"What server configuration variable should be changed to make -1 work?"

There is no server configuration variable that makes this work. I ran in to the same issue as you (while using a third party library) and discovered that those who were passing in -1 were pretty much lucky that it did work. Based on my research I believe what happened was one person used this, it worked, and the code just got copied into various projects without a real understanding of it's function. I say this because I see the same exact code, including comments, in various projects.

Later versions of the gd library changed the behavior some, breaking the imagerotate function for those who were passing in -1 as the background color.

Anyway, the solution is to use imagecolorallocatealpha to add a transparent "color" to the image palette, and pass that color as the background color to imagerotate. Your solution of: $tmp = imagerotate($tmp, $angle, imagecolorallocatealpha($tmp, 0, 0, 0 , 127)); should be just fine.



来源:https://stackoverflow.com/questions/24643783/php-gd-imagerotate-fails-when-1-is-passed-for-bgd-color

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!