PHP application PHP generates thumb images

I want to create an image thumbnail for a PDF file stored in a Google mat using imagick and PHP.
I am deploying my application in the standard Google engine standard system (GAE). The
problem is that I keep getting this error

Fatal error: Uncaught exception 'ImagickException' with message  
'UnableToWriteBlob `magick--1noB3XBwJhgfn': Read-only file system

I know that the file system on which the application is deployed is not writable, but I need a way to achieve it ...

this is my code

<?php
putenv('MAGICK_TEMPORARY_PATH='.sys_get_temp_dir());

$imagick = new Imagick();

// get the content of pdf url
$imagenblob=file_get_contents('http://www.pdf995.com/samples/pdf.pdf');      

// read the content and load it inn imagick instance
$imagick->readimageblob($imagenblob);                                        

// point to the first page, because I want thumbnail for first page
$imagick->setIteratorIndex(0);        

// set image format
$imagick->setImageFormat('png');       

// resize image
$imagick->resizeImage(320,320,Imagick::FILTER_LANCZOS,1,1);

// return the result
header("Content-Type: image/png");          
$base64 = 'data:image/png;base64,' . base64_encode($imagick);
exit($base64);

Maybe if I can change the directory that I use for writing imagick, but I could not achieve this!

+4
source share
4 answers

, , Google Compute Engine PHP, PDF Imagick base64.

Imagick PDF GAE

0

sandware:

App Engine :

( ) - , .

imagick, / ( , ), (donno, PHP , python ) , Imagick::setFilename.

setFormat setImageFormat, setImageFormat , / :

, Imagick:: setFormat . . TIFF, setFormat ('pdf') Imagick , writeImagesFile ('foo.pdf') getImagesBlob().

+1

- :

1) Google App Engine Standard 2) Imagick, -, ( , ) .

, Imagick, GAE Standard. GAE Flex Google Compute Engine. , Flex ; . microservice GAE Flex . . Google Cloud Storage ( GAE).

+1

ImageMagick , / . but in the documents it is proposed and . tempnam()sys_get_temp_dir()

putenv('MAGICK_TEMPORARY_PATH='.sys_get_temp_dir());
$imagick = new Imagick(); 
// ...

Also note that Ghostscript is used by ImageMagick for PDF decoding. Make sure the binary is gsinstalled and accessible when working with PDF files.

0
source

Source: https://habr.com/ru/post/1695349/


All Articles