Как из Intervention Image получить ресурс для imagepng? - PullRequest
0 голосов
/ 09 июля 2019

В приложении 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? Я правильно двигаюсь?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...