Page 1 of 1

Converting to PDF; Accurately Overlaying PDFs

Posted: 2017-04-04T11:53:27-07:00
by darkwingduke
Here are my specs:
Ubuntu 14.04
ImageMagick 6.7.7
Ghostscript 9.10
Imagick 3.4.0
PHP 5.6.18

Here's my situation:
I'm sending a canvas element into a PHP file via AJAX. I'm utilizing the Fabric.js library, so that I'm able to add and manipulate text on a canvas that is 1050px wide and 675px high. When I use Imagick, make the conversion to PDF, and send that file into a local folder, the end result looks great. The resolution, placement, and size of the text seems to be accurate.
In addition to converting that canvas element to a PDF, I'm also converting a local EPS file to a PDF. (I'm needing this image to serve as my background when I overlay the first image on top of it.) When I go through a similar conversion process with only this separate image, I get another great looking PDF as an end result.
However, when I use compositeImage to overlay the text PDF on top of the background PDF, the placement and size of the text is incorrect. (The resolution still looks good, though.) I'm using setSize to make the columns and rows of both PDFs identical (the same as the canvas element: 1050 x 675), so I'm not sure why this is happening. (I noticed when I look at the two separate image in Preview, that the Page sizes are different.) What am I missing?

Here's my PHP code:

Code: Select all

//First Image: Background Image
$background = ***local EPS file***
$background_image = new Imagick();

//Second Image: Text Image
$text = base64_decode($text_data);
$text_image = new Imagick();

//Combining Images
$background_image->compositeImage($text_image, imagick::COMPOSITE_ATOP, 0, 0);

Re: Converting to PDF; Accurately Overlaying PDFs

Posted: 2017-04-04T15:49:23-07:00
by snibgo
See the documentation . I suspect setSize doesn't do what you think it does.

Re: Converting to PDF; Accurately Overlaying PDFs

Posted: 2017-04-07T16:18:41-07:00
by darkwingduke
You're right. I don't think setSize was doing anything.

I went back and produced a new source image for my background and set my canvas to match those dimensions and it ended up working. I was being way too reliant on setSize.