Image rotation and white background in php
This is the original image:
This is the code I am using:
<?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);
?>
This is output:
In this image, the background is black. I want to make it white after rotation. could you help me?
+3
source to share
1 answer
please you can change your code the same as
$source = imagecreatefromjpeg($filename);
// Rotate
$transColor = imagecolorallocatealpha($source, 255, 255, 255, 127);
$rotate = imagerotate($source, $degrees,$transColor);
and try this, i hope it helps you in color, you can change it with any other color code.
+2
source to share