15

私は次のものを持っています:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Imagine\Image\Box;
use Imagine\Image\ImageInterface;
use Imagine;

class UploadController extends Controller {

    public function processImage($request) {
        $file = $request->file('file');

        $path = '/images';
        $fileName = 'image.png';

        if ($file) {
            $file->move('../public' . $path, $fileName);
            $gThumb = $this->createThumbnail(219, 300, '../public/images', 'image', 'png', 'thumb', true);
            $pThumb = $this->createThumbnail(300, 300, '../public/images', 'image', 'png', 'pthumb');
            return response()->json([
                'gallery_thumbnail' => $path . '/' . $gThumb,
                'upload_thumbnail' => $path . '/' . $pThumb
            ]);
        }
    }

    function createThumbnail($height, $width, $path, $filename, $extension, $postfix = null, $mask = null)
    {
        $mode = ImageInterface::THUMBNAIL_OUTBOUND;
        $size = new Box($width, $height);
        $postfix = $postfix ? $postfix : 'thumb';


        $thumbnail = Imagine::open("{$path}/{$filename}.{$extension}")->thumbnail($size, $mode);
        if ($mask) {
            $mask = Imagine::open('../public/images/masks/bubble-splash.png');
            $thumbnail->applyMask($mask);
        }
        $destination = "{$filename}" . "." . $postfix . "." . "{$extension}";

        $thumbnail->save("{$path}/{$destination}");
        return $destination;
    }
}

画像は期待どおりに保存されますが、サムネイルにマスクは適用されません。

どこが間違っていますか (私は Laravel 5 を使用しています)?


また、スクリプトを実行すると完了するまで文字通り約 1 分かかるため、何かを実行していますが、画像はマスクが適用されていないまま出力されます。


結局、私はこれらの人を使うつもりだと思いますhttps://www.imgix.com/

4

1 に答える 1

4

更新 2015-08-04 11:32 +0000

白の透明度は、Imagine で選択されたマスキング ロジックであることが判明しました。
https://github.com/avalanche123/Imagine/pull/449#issuecomment-127516157

オリジナル

これは、Imagine ライブラリのバグである可能性が最も高いです。私は以下を見つけました:

http://www.slideshare.net/avalanche123/introduction-toimagineの Reflection の例で説明されているように GD\Image::applyMask() を動作させることができなかったので、いくつか修正しました。

  1. マスクの RGB パレットのみを引き続きサポートしますが、色間の平均を考慮するようになりました。
  2. 透明度が 0.5 未満の場合、イメージが変わります。

https://github.com/avalanche123/Imagine/pull/449から

関連する修正がまだコミットされていない:
https://github.com/kasuparu/Imagine/commit/66a36652c76f9b5ff640f465d8f970c563841ae6

私は固定コードを試してみましたが、マスクが(私の観点から)後方に適用され、黒い部分を保持し、白い部分を破棄することを除いて、うまくいくようです。プルリクエストでこの問題についてコメントしました。

参考までに、これは実際の修正です。

$blackAmount の使用: php-imagine-applymask-using-blackamount-20150731-1831-gmt

$whiteAmount を使用して、私の修正を修正します。 php-imagine-applymask-using-whiteamount-20150731-1831-gmt

于 2015-07-31T18:47:13.900 に答える