Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to convert to image. #33

Open
ghost opened this issue Nov 8, 2017 · 1 comment
Open

Not able to convert to image. #33

ghost opened this issue Nov 8, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Nov 8, 2017

                  ` $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.

@vasilenka
Copy link

vasilenka commented Nov 15, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant