图像旋转和白色背景在PHP中

时间:2015-06-26 06:55:20

标签: php

这是原始图片:

enter image description here

这是我正在使用的代码:

<?php
$filename = 'image.jpg';
$degrees = 135;

// Content type
header('Content-type: image/jpeg');

// Load
$source = imagecreatefromjpeg($filename);

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

// Output
imagejpeg($rotate);

// Free the memory
imagedestroy($source);
imagedestroy($rotate);
?>

这是输出:

enter image description here

在这张照片中,背景是黑色的。我希望在旋转后使其变白。你能帮帮我吗?

1 个答案:

答案 0 :(得分:2)

请你可以改变你的代码

$source = imagecreatefromjpeg($filename);
// Rotate
$transColor = imagecolorallocatealpha($source, 255, 255, 255, 127);
$rotate = imagerotate($source, $degrees,$transColor);

并试试这个我希望它能帮你上色,你可以用任何其他颜色代码改变它