如何从干预图像获取imagepng的资源?

时间:2019-07-09 15:34:10

标签: laravel-5 intervention

在laravel 5.8应用程序中,我想以编程方式生成横幅广告,例如基本图像,左侧图像,中央文本,右侧水印。 我这样做是:

        // create new *Intervention Image*
        $img = \Image::make( public_path('foo.jpg') );

// paste another image
        $img->insert( public_path('bar.png') );

// create a new Image instance for inserting
        $watermark = \Image::make( public_path('watermark.png') );
        $img->insert($watermark, 'center');

        // insert watermark at bottom-right corner with 10px offset
        $img->insert( public_path('watermark.png'), 'bottom-right', 10, 10);



        // create Image from file
        $img = \Image::make( public_path('foo.jpg') );

// write text
        $img->text('The quick brown fox jumps over the lazy dog.');

// write text at position
        $img->text('The quick brown fox jumps over the lazy dog.', 120, 100);

// use callback to define details
        $img->text('foo', 0, 0, function($font) {
            $font->file( public_path('fonts/themify/themify.ttf') );
            $font->size(24);
            $font->color('#fdf6e3');
            $font->align('center');
            $font->valign('top');
            $font->angle(45);
        });

//        var_dump($img);

        // draw transparent text
        $img->text('foo', 0, 0, function($font) {
            $font->color(array(255, 255, 255, 0.5));
        });

        header('Content-Type: image/png');
        imagepng($img, null, 100);
//        imagedestroy($img); //Free up memory

我得到了错误:

imagepng() expects parameter 1 to be resource, object given

倾销我得到的$ img:

object(Intervention\Image\Image)#910 (9) { ["driver":protected]=> object(Intervention\Image\Gd\Driver)#907 (2) { ["decoder"]=> object(Intervention\Image\Gd\Decoder)#908 (1) { ["data":"Intervention\Image\AbstractDecoder":private]=> NULL } ["encoder"]=> object(Intervention\Image\Gd\Encoder)#905 (4) { ["result"]=> NULL ["image"]=> NULL ["format"]=> NULL ["quality"]=> NULL } } ["core":protected]=> resource(45) of type (gd) ["backups":protected]=> array(0) { } ["encoded"]=> string(0) "" ["mime"]=> string(10) "image/jpeg" ["dirname"]=> string(40) "/mnt/_work_sdb8/wwwroot/lar/votes/public" ["basename"]=> string(7) "foo.jpg" ["extension"]=> string(3) "jpg" ["filename"]=> string(3) "foo" }

我看到$ img具有受保护的资源属性。如何从$ img中获取imagepng? 我以有效的方式移动吗?

0 个答案:

没有答案