Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
I am new to imagemagick and am trying to convert ".png" and ".jpg" image files to pdf using an aws lambda / node.js function, but the result is a file without the pdf files header.
Can anyone tell me if there is any restriction for this?
I am reading a file from aws S3, saving in /tmp and then executing the command:
if I change the file extension to ".jpg" or ".png" I can see the generated file, but not with the ".pdf" extension. Looks like if the imagemagick was not doing the conversion.
Any idea?
Hi Guys.
Has anyone ever converted a ".jpg" or ".png" image file to PDF using imagemagick with AWS lambda?
Using the command line in my computer I can do the conversion normally but via AWS Lambda does not.
Basically I'm reading an image file from AWS S3 and saving in the /tmp. Then I execute the IM convert command.
After the conversion I'm reading the converted file to put in the buffer and save again in the AWS S3:
// put image file to buffer
let buffIn = new Buffer.from(response.Body, 'base64');
// write image file to /tmp
fs.writeFile(('/tmp/input-'+ srcKey), buffIn, function(err) {
// If an error occurred, show it and return
if(err) {
console.log('error:%s',err);
} else {
//Loop through the sizes and perform resizing for each available options
_sizesArray.forEach(function (value, key) {
let dstKey = _sizesArray[key].outFilename;
// transform, and upload to S3 with different FileNames
async.waterfall([
.
.
.
.
im.convert([('/tmp/input-' + srcKey), ('/tmp/' + dstKey)], function(err, res) {
Where:
/tmp/input-' + srcKey = Source Image File Name with ".jpg" extension
/tmp/' + dstKey = Destination Image File Name with ".pdf" extension
No errors is generated and the generated Destination file is identical to the source file, just with the extension changed to ".pdf".
I installed ghostscript and put it in the package sent to Lambda but it did not change anything.
Anyone have any idea what the problem might be?
Imagemagick is a raster processor. So note that if you convert a raster image to PDF, it will be a raster image in a vector PDF shell. It will not be converted to vector. For that you need a tool such as potrace.
Note that you might have to modify your policy.xml file to permit reading and writing PDF files.
Thanks snibgo and fmw42.
I just strange that I can do size conversions and apply profile files, but conversion to PDF did not work.
I'll do some more testing, thank you.
In the policy.xml file I have the following lines:
</policymap>
<policy domain="module" rights="read|write" pattern="{EPS,PS2,PS3,PS,PDF,XPS}" />
<policy domain="module" rights="read|write" pattern="{GIF,JPEG,PNG,WEBP,JPG`}" />
<policy domain="coder" rights="read|write" pattern="{GIF,JPEG,PNG,WEBP,JPG}" />
<policy domain="coder" rights="read|write" pattern="{EPS,PS2,PS3,PS,PDF,XPS}" />
and using the command identify -list policy we have:
With this configuration I can convert image file to PDF in may computes, but not in the AWS Lambda.
Looking for the package created for the AWS Lambda function I don't see this file, so that may be the problem.
I'm going to do some testing to see the result of the "identify -list policy" command in aws lambda.
Hi fmw42.
No, from what I saw, in the instance where the function runs, the policy.xml file is not enabled to work with PDF files.
I am looking to see if it is possible to somehow change the aws lambda instance policy.xml configuration.