1

IMagick PHP ラッパーを使用して、指定された画像を一連のタイル (可変数) に分割するのを支援しようとしています。

ImageMagick のドキュメントには-crop、オプションのフラグを受け入れるオペレーターへの参照があります。これは@、イメージを「ほぼ同じサイズの分割」にカットするように指示し (ここを参照)、イメージのサイズが目的のタイル サイズの正確な倍数。

IMagick PHP ラッパーでこの機能を活用する方法があるかどうかは誰にもわかりませんか? 他に使えるものはありcropImage()ますか?

4

1 に答える 1

1

私は同じことをしなければなりませんでした(あなたの質問を正しく読んでいれば)。それはcropImageを使用しますが...


function slice_image($name, $imageFileName, $crop_width, $crop_height)
{

$dir = "dir where original image is stored"; $slicesDir = "dir where you want to store the sliced images; mkdir($slicesDir); //you might want to check to see if it exists first....

$fileName = $dir . $imageFileName;

$img = new Imagick($fileName); $imgHeight = $img->getImageHeight(); $imgWidth = $img->getImageWidth();

$crop_width_num_times = ceil($imgWidth/$crop_width); $crop_height_num_times = ceil($imgHeight/$crop_height); for($i = 0; $i < $crop_width_num_times; $i++) { for($j = 0; $j < $crop_height_num_times; $j++) { $img = new Imagick($fileName); $x = ($i * $crop_width); $y = ($j * $crop_height); $img->cropImage($crop_width, $crop_height, $x, $y); $data = $img->getImageBlob();

  $newFileName = $slicesDir . $name . "_" . $x . "_" . $y . ".jpg";
  $result = file_put_contents ($newFileName, $data);
}

} }

于 2011-05-13T12:07:04.967 に答える