phantommagick
phantommagick copied to clipboard
Not able to convert to image.
` $html = View::make('test', ['pickup'=> $pickup])->render();
$view = (string)$html;
$conv = new \Anam\PhantomMagick\Converter();
$client = S3Client::factory([
'credentials' => [
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
],
'region' => env('AWS_REGION'),
'version' => 'latest',
]
);
$options = [
'width' => 1280,
'quality' => 90
];
$conv->adapter($client, env('AWS_BUCKET'))
->source($view)
->setImageOptions($options)
->toPng()
->save('try.png');
return response()->json("done");
}`
I am not able to convert html file stored in my local to image. When I use addPage it converts image to pdf with .png extension
$conv->adapter($client, env('AWS_BUCKET')) ->addPage($view) ->setImageOptions($options) ->toPng() ->save('try.png'); return response()->json("done");
Using a url I am able to store image to my s3 bucket but not with local html file.
Need help asap.
Hey @swapu258, I am working on laravel project and I got the same problem too. Here's a working solution for me.
Seems like the problem is this
$html = View::make('test', ['pickup'=> $pickup])->render();
$view = (string)$html;
source()
method only works with the path to the file, we can't just pass the $view
.
So what I did was, I create a file in public folder (e.g. generated.html) and pass $html to the generated.html using laravel File::put()
. Then create $path
and assign the path to the generated.html, and pass $path
to the source()
method.
P.S. Since it's not safe to have something on public folder, after the save()
method, I just pass empty string to the $html
.
I hope I'm not too late.