Dziękuję za odpowiedź . Użyłem twojej funkcji i dodałem kolejną pętlę, aby zmienić kolor zewnętrznego piksela kwadratów za pomocą funkcji o nazwie imagelinethick w http://www.php.net/manual/en/function.imageline.php.Więc stało się:
<?php
$image = imagecreatefromjpeg('Penguins.jpg');
$imagex = imagesx($image);
$imagey = imagesy($image);
$pixelate_y=10;
$pixelate_x=10;
$height=$imagey;
$width=$imagex;
for($y = 0;$y < $height;$y += $pixelate_y+1)
{
for($x = 0;$x < $width;$x += $pixelate_x+1)
{
// get the color for current pixel
$rgb = imagecolorsforindex($image, imagecolorat($image, $x, $y));
// get the closest color from palette
$color = imagecolorclosest($image, $rgb['red'], $rgb['green'], $rgb['blue']);
imagefilledrectangle($image, $x, $y, $x+$pixelate_x, $y+$pixelate_y, $color);
}
}
for($y = 0;$y < $height;$y += $pixelate_y+1)
{
for($x = 0;$x < $width;$x += $pixelate_x+1)
{
//make a border line for each square
$rgb = imagecolorsforindex($image, imagecolorat($image, $x, $y));
$color = imagecolorclosest($image, 123, 123, 123);
imagelinethick($image, $x, $y, $x, $y+$pixelate_y, $color, 1);
imagelinethick($image, $x, $y, $x+$pixelate_x, $y, $color, 2);
}
}
function imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1)
{
/* this way it works well only for orthogonal lines
imagesetthickness($image, $thick);
return imageline($image, $x1, $y1, $x2, $y2, $color);
*/
if ($thick == 1) {
return imageline($image, $x1, $y1, $x2, $y2, $color);
}
$t = $thick/2 - 0.5;
if ($x1 == $x2 || $y1 == $y2) {
return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
}
$k = ($y2 - $y1)/($x2 - $x1); //y = kx + q
$a = $t/sqrt(1 + pow($k, 2));
$points = array(
round($x1 - (1+$k)*$a), round($y1 + (1-$k)*$a),
round($x1 - (1-$k)*$a), round($y1 - (1+$k)*$a),
round($x2 + (1+$k)*$a), round($y2 - (1-$k)*$a),
round($x2 + (1-$k)*$a), round($y2 + (1+$k)*$a),
);
imagefilledpolygon($image, $points, 4, $color);
return imagepolygon($image, $points, 4, $color);
}
header("Content-Type: image/JPEG");
imageJPEG($image, "", 75);
?>
Rezultatem jest tak: http://www.flickr.com/photos/[email protected]/6759029339/
Ale myślę, że to nadal potrzebują poprawy, aby uczynić go bardziej płynne.
obrazu łączyłeś wygląd, jakby pochodził z filtra Photoshopa. Prawdopodobnie nie będziesz w stanie odtworzyć tego dokładnego wyglądu bez jakiegoś ładnego programowania manipulacji z ostrym obrazem. Czy możesz utworzyć zestaw przykładowych obrazów, jeden "przed" i jeden "po", który pokazuje dokładny efekt, którego szukasz? – Charles
Dla efektu pixelate, myślę, że to jest jak patchworkowy filtr w Photoshopie. Jak mogę to zrobić? – just2cya
http://www.flickr.com/photos/[email protected]/6729984045/ Tworzę to przy użyciu tekstury patchworku Photoshopa, a dla dolnego obrazu używam zamieniać kolor. – just2cya