我想使用imagick和PHP生成存储在Google存储桶中的PDF文件的缩略图
我在google app engine(GAE)标准环境中部署我的应用程序
问题是我一直收到这个错误
Fatal error: Uncaught exception 'ImagickException' with message
'UnabletoWriteBlob `magick--1noB3XBwJhgfn': Read-only file system
我知道应用程序部署到的文件系统是不可写的,但我需要一种方法来实现这一点……
这是我的代码
<?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);
也许如果我可以改变想象用来写的目录,但我无法实现这一点!
解决方法:
由于两种相反的力量起作用,没有真正的方法来完成这项工作:
1)Google App Engine Standard的沙箱限制
2)Imagick显然需要本地文件系统访问(至少是暂时的)才能工作.
因此,如果您无法改变Imagick的工作方式,那么唯一剩下的解决方案就是不使用GAE Standard.您可以使用GAE Flex或Google Compute Engine.我不知道为什么Flex不适合你;你不需要移动整个项目.您可以在同一项目中将此部分作为microservice在GAE Flex上移植.该服务的唯一功能是处理图像并获取缩略图.然后,您可以将缩略图放在Google云端存储分区中,以便您的应用程序的其余部分(使用GAE标准版)使用.