は、あなたの答えをありがとうは、 。私はあなたの関数を使用してhttp://www.php.net/manual/en/function.imageline.phpのimagelinethickという関数を使って四角形の外側のピクセルの色を変更する別のループを追加しました。だから、となりました:
<?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);
?>
結果はこのようなものです:http://www.flickr.com/photos/[email protected]/6759029339/
しかし、私は、これはまだそれがよりスムーズにするために、いくつかの改善が必要だと思います。
をイメージPhotoshopのフィルタのように見えます。かなりハードコアの画像操作プログラミングがなければ、その正確な外観を再現することはできません。あなたは探している正確な効果を示す "前"と "後"のサンプル画像を作成できますか? – Charles
pixelate効果については、Photoshopのパッチワークフィルターのようだと思います。どうやってやるの? – just2cya
http://www.flickr.com/photos/52700219NN6/6729984045/ 私はこれをPhotoshopパッチワークフィルタテクスチャを使用して作成し、下の画像では色を置き換えます。 – just2cya