<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja"
xml:lang="ja" dir="ltr">
<head>
<title>sample1125(ImageMagick6.5.2)</title>
</head>
<body>
<?php
/* 分割数 */
$divx=3;
$divy=3;
/* 傾き角度範囲 */
$mina=-5;
$maxa=5;
$im = new Imagick("sf.jpg");
$iw = $im->getImageWidth();
$ih = $im->getImageWidth();
$im2 = new Imagick();
$im2->newImage($iw+$divx*23+10, $ih+$divy*23+10, "white");
$bw = floor($iw/$divx);
$bh = floor($ih/$divy);
$idraw = new ImagickDraw();
for($ly=0;$ly<$divy;$ly++){
for($lx=0;$lx<$divx;$lx++){
$tbw=($lx==$divx-1)?$iw-($divx-1)*$bw:$bw;
$tbh=($ly==$divy-1)?$ih-($divy-1)*$bh:$bh;
$tim = $im->clone();
$tim->cropImage($tbw, $tbh,
$bw*$lx, $bh*$ly);
$tim->setImageBackgroundColor("black");
$tim->polaroidImage($idraw, rand($mina,$maxa));
$im2->compositeImage($tim, Imagick::COMPOSITE_OVER,
($bw+23)*$lx, ($bh+23)*$ly, Imagick::CHANNEL_ALL);
$tim->destroy();
}
}
$im2->writeImage('sample1125a.png');
$idraw->destroy();
$im2->destroy();
$im->destroy();
?>
<img src="sample1125a.png" /><br />
</body>
</html>
元画像(sf.jpg)
出力画像(sample1125a.png)
No comments:
Post a Comment