【问题标题】:Not getting transparent background while rotating an image旋转图像时没有获得透明背景
【发布时间】:2014-05-02 06:16:47
【问题描述】:

我想将具有透明背景填充的图像旋转到未覆盖的区域。

我参考了this官方文档的语法

// Rotate
$rotate = imagerotate($source, $degrees, 0);

但没有成功。

旋转后,我将黑色填充到未覆盖区域的图像。如下所示

原图为here

我也试过下面的命令

$> convert -rotate 5 image.png image_rotated.png

参考是this

上面的命令我在 png 和 jpg 图像上使用过,但是我没有得到结果..

现在我不知道哪里出了问题??我使用的库版本有什么问题吗??

我的php版本是PHP 5.4.9-4ubuntu2.4

提前致谢。

【问题讨论】:

标签: php image image-processing imagemagick image-rotation


【解决方案1】:

以下命令在Debian wheezy 7.5mageMagick 6.7.7-10 上为我工作。

convert -background "rgba(0,0,0,0)" -rotate 5 images.jpg new.png

指定-background "rgba(0,0,0,0)" 它将为输出图像设置透明背景填充。还要确保将输出图像保存为.png 格式(支持透明度)

希望它会有所帮助。 :)

注意:默认情况下-rotate 选项使用黑色颜色来填充背景。

编辑:

确保imagemagick 包已正确安装。

查看版本详情:

$convert --version
Version: ImageMagick 6.7.7-10 2014-03-08 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP 

如果您没有得到类似的输出,请尝试检查软件包的安装。

$sudo dpkg --get-selection | grep imagemagick

如果在上述命令的输出中其状态为deinstalled,您可能需要安装它。

$sudo apt-get install imagemagick

【讨论】:

  • 哇,我为你感到高兴,至少我让你过得愉快,祝你有美好的一天,祝你好运:D
【解决方案2】:

由于您使用的是 php,我假设您会接受 css 代码作为答案?将这些 CSS 添加到您的图像中,它会倾斜

/* Firefox */
-moz-transform:rotate(45deg);
/* Safari and Chrome */
-webkit-transform:rotate(45deg);
/* Opera */
-o-transform:rotate(45deg);
/* IE9 */
-ms-transform:rotate(45deg);

编辑: 所以不是 css 呵呵,试试这个吧

$source = imagerotate($source,$degree,0XFFFFFF00,0); //<-- FFFFFF00 = RRGGBBAA
//you might not need to disable blending, try if it's not working
//imagealphablending($source, false);
imagesavealpha($source, true);
//then user $source however you want

【讨论】:

  • 感谢您对我的问题感兴趣,但我需要旋转图像,然后以某个角度将其叠加到另一个大图像上。同样的方式有数百张图像,并且从这些图像中创建一个视频文件,该文件将显示在网络上。我不需要在浏览器上显示任何图像。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多