// rotate image
if ($gd_version >= 2 && is_numeric($this->image_rotate)) {
if (!in_array($this->image_rotate, array(0, 90, 180, 270))) $this->image_rotate = 0;
if ($this->image_rotate != 0) {
if ($this->image_rotate == 90 || $this->image_rotate == 270) {
$tmp = $this->imagecreatenew($this->image_dst_y, $this->image_dst_x);
} else {
$tmp = $this->imagecreatenew($this->image_dst_x, $this->image_dst_y);
}
$this->log .= '- rotate image : ' . $this->image_rotate . '<br />';
for ($x = 0; $x < $this->image_dst_x; $x++) {
for ($y = 0; $y < $this->image_dst_y; $y++){
if ($this->image_rotate == 90) {
imagecopy($tmp, $image_dst, $y, $x, $x, $this->image_dst_y - $y - 1, 1, 1);
} else if ($this->image_rotate == 180) {
imagecopy($tmp, $image_dst, $x, $y, $this->image_dst_x - $x - 1, $this->image_dst_y - $y - 1, 1, 1);
} else if ($this->image_rotate == 270) {
imagecopy($tmp, $image_dst, $y, $x, $this->image_dst_x - $x - 1, $y, 1, 1);
} else {
imagecopy($tmp, $image_dst, $x, $y, $x, $y, 1, 1);
}
}
}
if ($this->image_rotate == 90 || $this->image_rotate == 270) {
$t = $this->image_dst_y;
$this->image_dst_y = $this->image_dst_x;
$this->image_dst_x = $t;
}
// we transfert tmp into image_dst
$image_dst = $this->imagetransfer($tmp, $image_dst);
}
}
// add color overlay
if ($gd_version >= 2 && (is_numeric($this->image_overlay_percent) && $this->image_overlay_percent > 0 && !empty($this->image_overlay_color))) {
$this->log .= '- apply color overlay<br />';
sscanf($this->image_overlay_color, "#%2x%2x%2x", $red, $green, $blue);
$filter = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
$color = imagecolorallocate($filter, $red, $green, $blue);
imagefilledrectangle($filter, 0, 0, $this->image_dst_x, $this->image_dst_y, $color);
$this->imagecopymergealpha($image_dst, $filter, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_overlay_percent);
imagedestroy($filter);
}
// add brightness, contrast and tint, turns to greyscale and inverts colors
if ($gd_version >= 2 && ($this->image_negative || $this->image_greyscale || is_numeric($this->image_threshold)|| is_numeric($this->image_brightness) || is_numeric($this->image_contrast) || !empty($this->image_tint_color))) {
$this->log .= '- apply tint, light, contrast correction, negative, greyscale and threshold<br />';
if (!empty($this->image_tint_color)) sscanf($this->image_tint_color, "#%2x%2x%2x", $tint_red, $tint_green, $tint_blue);
imagealphablending($image_dst, true);
for($y=0; $y < $this->image_dst_y; $y++) {
for($x=0; $x < $this->image_dst_x; $x++) {
if ($this->image_greyscale) {
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
$r = $g = $b = round((0.2125 * $pixel['red']) + (0.7154 * $pixel['green']) + (0.0721 * $pixel['blue']));
$color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']);
imagesetpixel($image_dst, $x, $y, $color);
}
if (is_numeric($this->image_threshold)) {
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
$c = (round($pixel['red'] + $pixel['green'] + $pixel['blue']) / 3) - 127;
$r = $g = $b = ($c > $this->image_threshold ? 255 : 0);
$color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']);
imagesetpixel($image_dst, $x, $y, $color);
}
if (is_numeric($this->image_brightness)) {
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
$r = max(min(round($pixel['red'] + (($this->image_brightness * 2))), 255), 0);
$g = max(min(round($pixel['green'] + (($this->image_brightness * 2))), 255), 0);
$b = max(min(round($pixel['blue'] + (($this->image_brightness * 2))), 255), 0);
$color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']);
imagesetpixel($image_dst, $x, $y, $color);
}
if (is_numeric($this->image_contrast)) {
$pixel = imagecolorsforindex($image_dst, imagecolorat($image_dst, $x, $y));
$r = max(min(round(($this->image_contrast + 128) * $pixel['red'] / 128), 255), 0);
$g = max(min(round(($this->image_contrast + 128) * $pixel['green'] / 128), 255), 0);
$b = max(min(round(($this->image_contrast + 128) * $pixel['blue'] / 128), 255), 0);
$color = imagecolorallocatealpha($image_dst, $r, $g, $b, $pixel['alpha']);
imagesetpixel($image_dst, $x, $y, $color);