Comments (12)
Hey, so AWS lambda comes with built-in unless you need Imagemagick 7 or another delegate
from imagemagick-aws-lambda-2.
Hey, I read that. I decided to create my own layer as follows.
- Launched an EC2 Tiny with Ubuntu server 18.04.
- I executed the following commands:
cd $HOME mkdir -p temp/python cd temp/python pip install Wand -t . cd .. zip -r9 ../wand.zip .
- I uploaded this zip as a layer.
Then when I run next lambda code:
import json
import boto3
from PyPDF2 import PdfFileReader, PdfFileWriter
import io
import os
from wand.image import Image
def lambda_handler(event, context):
s3 = boto3.client('s3')
#Accedo a un fichero del s3, lo leeo entero y lo transformo en un objeto de tipo BytesIO para que lo pueda leer el pdf File reader
stream = io.BytesIO(s3.get_object(Bucket=os.environ["bucket"], Key=os.environ["rutaArchivo"])['Body'].read())
pdf = PdfFileReader(stream)
pages = pdf.getNumPages()
print("number of pages: %i" % pages)
for i in range(pdf.getNumPages()):
output = PdfFileWriter()
output.addPage(pdf.getPage(i))
tmp = io.BytesIO()
output.write(tmp)
tmp.seek(0)
img = Image(file = tmp, resolution = 72)
img.convert("png")
nombre="paginas/pagina"+str(i)+".png"
s3.upload_fileobj(img, os.environ["bucket"],nombre )
return {
'statusCode': 200,
'body': json.dumps(pages)
}
As you can see, I was trying to split a pdf from a S3 bucket into pages in PNG format
I get this error:
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 29, in lambda_handler
img = Image(file = tmp, resolution = 72)
File "/opt/python/wand/image.py", line 8207, in __init__
self.read(file=file, resolution=resolution, units=units)
File "/opt/python/wand/image.py", line 8686, in read
self.raise_exception()
File "/opt/python/wand/resource.py", line 240, in raise_exception
raise e
wand.exceptions.MissingDelegateError: no decode delegate for this image format `' @ error/blob.c/BlobToImage/365
END RequestId: 8a4b5fee-721e-4ab7-b882-c8dd8dd786f0
REPORT RequestId: 8a4b5fee-721e-4ab7-b882-c8dd8dd786f0 Duration: 2681.02 ms Billed Duration: 2700 ms Memory Size: 128 MB Max Memory Used: 101 MB
So as I saw in a website it looks like no Imagemagick was provided by AWS Lambda.
What could be causing this error?
from imagemagick-aws-lambda-2.
So the error you are getting is an issue with the PDF format not being supported
In my opinion, the imagemagick that's bundled into Lambda is the one that is being called with your code
from imagemagick-aws-lambda-2.
@stojanovic @simalexan It would be cool if there was a version of this layer that gave a way for us to use ImageMagick's API's with tools like Wand
from imagemagick-aws-lambda-2.
So the error you are getting is an issue with the PDF format not being supported
In my opinion, the imagemagick that's bundled into Lambda is the one that is being called with your code
What can I do for solving the problem? Any idea?
from imagemagick-aws-lambda-2.
So you need to compile ImageMagick into static binaries and then you need to point wand to those static binaries by using MAGICK_HOME
However, I have been trying this the last few days and have not really got anywhere...
from imagemagick-aws-lambda-2.
I haved read that too.
I have tried right now the next code:
with Image() as pdf:
pdf.format='pdf'
pdf.read(blob=stream)
#pdf = Image(format="pdf",blob=stream,resolution=300)
pdfImage = pdf.convert("jpeg")
i=1
for img in pdfImage.secuence:
page = Image(image=img)
tmp = io.BytesIO()
tmp.seek(0)
page.save(file=tmp)
nombre="paginas/pagina"+str(i)+".jpeg"
s3.upload_fileobj(tmp, os.environ["bucket"],nombre )
And throws me the next error:
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 37, in lambda_handler
pdf.format='pdf'
File "/opt/python/wand/image.py", line 1733, in format
raise ValueError(repr(fmt) + ' is unsupported format')
ValueError: 'pdf' is unsupported format
END RequestId: 81892afc-a49d-4634-9d99-385ef21b0a93
REPORT RequestId: 81892afc-a49d-4634-9d99-385ef21b0a93 Duration: 2367.02 ms Billed Duration: 2400 ms Memory Size: 128 MB Max Memory Used: 100 MB
I have read in Imagemagick website that it needs ghostscript for reading pdfs.
EDIT
I Executed next command on aws lambda:
identify -list format
Which list formats accepted by Imagemagick in that system. PDF format is not present!
from imagemagick-aws-lambda-2.
@WaterKnight1998 this version of imagemagick does not come with ghostscript, and imagemagick needs ghostscript for PDF support. you will need to modify the makefile to compile and include ghostscript libraries if you want pdf support. alternatively, skip over imagemagick, wand and the whole stack and just install ghostscript directly to your Lambda, then convert PDFs using a subprocess
from imagemagick-aws-lambda-2.
@WaterKnight1998 this version of imagemagick does not come with ghostscript, and imagemagick needs ghostscript for PDF support. you will need to modify the makefile to compile and include ghostscript libraries if you want pdf support. alternatively, skip over imagemagick, wand and the whole stack and just install ghostscript directly to your Lambda, then convert PDFs using a subprocess
How can i include ghostscript libraries on aws lambda? I found layer for nodejs. However i need it for python3!
What should i modify from ImageMagick´s makefile to include ghostscript?
from imagemagick-aws-lambda-2.
the layer for nodejs will work for python as well, it's just a linux binary
from imagemagick-aws-lambda-2.
So, which layers do i need to make imagemagick work with ghostscript?
How can i use a subprocess to invoke ghostscript? Can you show me any example, pls?
from imagemagick-aws-lambda-2.
@WaterKnight1998 i'm posting this so you know I'm not ignoring you, but you're asking for something requiring far more time than I have to field community github requests. maybe someone else has more time to help, sorry
from imagemagick-aws-lambda-2.
Related Issues (20)
- lambda with imagemagick not working 10.x HOT 3
- Python 3.8 is running based on Amazon Linux 2 HOT 1
- update example to include AWS-CDK usage HOT 1
- Looking for guidance
- Can current AWS Lambda Layer support nodejs 12? HOT 1
- question on usage in layer HOT 7
- Adding libheif support breaks build HOT 7
- Help for adding jxrlib to the layer
- Support for AVIF
- SNS Event Notification Not Passing bucket name in example
- [SUGGESTION] Removing lib before make deploy could reduce size of the layer drastically
- LCMS delegate missing HOT 1
- AWS Lambda Layer in AWS Serverless App Repository does not list nodejs 12 as a compatible layer HOT 2
- Convert Issue (Possibly fixed by latest Image Magick build)
- drawText doesn't appear to work with this layer HOT 2
- Does this support arm64 architectures? HOT 4
- AccessDenied
- Is MONTAGE also included in this?
- Using ImageMagick has some vulnerability HOT 1
- Ask for update to lastest ImageMagick and Nodejs HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imagemagick-aws-lambda-2.