0

私は96x96の画像を持っており、それを16x16の36個に分割する必要があります。以下に示すスクリプトは、ローカルホストでは正常に機能しますが、ウェブホストでは機能しません。

    function makeTiles($name, $imageFileName, $crop_width, $crop_height)
    {
    $dir = "/pic";
    $slicesDir = "/pic/16X16";

    // might be good to check if $slicesDir exists etc if not create it.
    $ImgExt = split(".",$imageFileName);
    $inputFile = $dir . $imageFileName;

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

    $cropWidthTimes = ceil($imgWidth/$crop_width);
    $cropHeightTimes = ceil($imgHeight/$crop_height);
    for($i = 0; $i < $cropWidthTimes; $i++)
    {
        for($j = 0; $j < $cropHeightTimes; $j++)
        {
            $img = new Imagick($inputFile);
            $x = ($i * $crop_width);
            $y = ($j * $crop_height);
            $img->cropImage($crop_width, $crop_height, $x, $y);
            $data = $img->getImageBlob();
            $newFileName = $slicesDir . $name . "_" . $x . "_" . $y . ".".$ImgExt[1];
            $result = file_put_contents ($newFileName, $data);
        }
    }
}

致命的なエラーが発生する

Fatal error: Class 'Imagick' not found in myfile.php line number

私のホストは言っています:

Imagickとimagemagicはどちらも残念ながら同じですが、ImageMagickバイナリのようなバイナリを持っているPHPモジュールとしてはありません。また、Imagemagicパスは/usr / local/binです。この関数をスクリプトに含めて、Webサイトの機能を自分の側から確認してください。

このエラーを修正する方法がわかりません。

4

1 に答える 1

2

私が正しく理解している場合は、次をimagick使用してスクリプトからバイナリを呼び出す必要がありexec()ます。

 exec('/usr/local/bin/convert '.$inputFile.' -crop 96x96+ox+oy '.$newFilename);

およびは、正しいオフセット値に置き換える必要がありますoxoy

これが役立つかもしれないいくつかのリンクです:

  1. PHPのImagickバイナリを使用するにはどうすればよいですか
  2. Imagick-コマンドラインツールの変換
于 2012-04-25T05:34:55.750 に答える