Creating high quality images for printing (CMYK) on websdrver - php

I'm struggling with generating high-quality images for printing - mainly because there is really poor support for CMYK colors in PHP libraries and Linux CLI tools.
The situation is as follows. I have input materials in tiff format and CMYK colors - it is the background. I need to add some text to it and save as tiff with CMYK colors. The challenge is to use exact CMYK colors (so no temporary export/import to sRGB during the process is possible).
My first thought was to use Imagemagick but Imageimagick has no option to draw in CMYK. I need to work in sRGB and export material to CMYK. So some information about colors are changed during the process.
It seems this is not possible with PHP to add text to image without temporarily converting colors to sRGB, so I'm looking for any option like Linux CLI tool, node.js lib, etc. The goal is to at least generate text as an image with a transparent background and with colors defined in CMYK with exact values or do the same directly on the background image.

Finally, I gave up with Imagemagick. As we can use PDF for professional printing I decided to go this way.
I installed TCPDF and TCPDI. With TCPDI I imported previously prepared pdf template with graphics etc. Using TCPDF I added necessary dynamic text - TCPDF support CMYK with no issues.
Depending on where you print you can embed fonts to PDF (it can be done with TCPDF) or change texts to outlines which is a small challenge. I needed to change fonts to outlines (client request) so I did it with Ghostscript.
It took me a whole day to figure it out, so I post it in case somebody will have a similar problem. Definitely not an answer to the question, but at least a good solution for the problem itself.

Related

PDF Watermark with: Transparency, underlined, bold and Italicized Text Ghostscript and Php

I am trying to watermark( with text ) pdf with ghostscript. Earlier, I added page numbers via ghostscript, even text based watermark in pdf but transparency and watermark above and below the content seem to be an issue and for that i have had failed attempts with Postscript's PDFMARK extension. Below is the ps code(In the body of EndPage), i have deliberately tried to write the text instead of Stroke in order to allow bold, italics and underlines. I am considering to change from php to any other language if it offers a free alternative to this.
/Helvetica 44 selectfont
(Shadab Hussain Watermark on Test)
dup
stringwidth pop
currentpagedevice /PageSize get 0 get
exch sub 2 div
currentpagedevice /PageSize get 1 get 2 div moveto
show
You can't do transparency in PostScript, because it isn't supported in the graphics model. This is one of the major differences between PostScript and PDF.
Ghostscript does have some extensions to the PostScript imaging model which will allow some use of PDF transparency from PostScript, but it's non-trivial. You should (using the latest HEAD from the Ghostscript Git repository) look at ghostpdl/examples/transparency_example.ps for an example of using transparency from PostScript. Note that these extensions are totally Ghostscript-specific and will not work with any other PostScript interpreter.
As regards 'above' and 'below' the content. You either execute the PostScript program on BeginPage, in which case it is laid down before the PDF content, and may be overwritten by it (hint: many PDF files start by drawing a white rectangle covering the page), or you execute the PostScript program on EndPage (both is also possible), in which case it overwrites the already drawn content.

Library to create print-ready charts in PDF using PHP 5.3

I have to create some nicely formatted charts (bar and 3D pie) from dynamic data using PHP 5.3 and for output as PDF report. The report is not to be rendered to the screen at all. I have made the charts using pChart2 as .png files and imported them using tcpdf. The system works, but the quality level is poor, rendering text as a graphic causes the font edges to be blurry etc. when printed. I tweaked the image size of the .PNG output, and it made some improvements but it increases the file size, and the text still looks blurry.
So what I am after is a library to create charts using PHP that can be exported to .svg or .eps format, so elements are drawn by the printer and render sharply for print. Using TCPDF I have imported our logos that are in .EPS format, and the difference between the images is quite marked.
I have seen there is a library called ezcomponents that i can give a try. But before I dive in, is there any advice on what to try before proceeding?
I have had reasonable success rendering the images on a canvas that is two to three times larger than what I ultimately need and then, once I'm finished, using the imagecopyrresampled() function to copy the large image onto a canvas with smaller dimensions, which I save as a png and add to the PDF file. The dithering is pretty good and curved lines, in particular, benefit greatly from this approach. Text might not benefit quite as much, but its worth trying, because it should require very few changes to your code to experiment with this approach.

Bad CMYK to RGB conversion with GD

I am doing the standard image optimise / resize technique with PHP and GD, basically:
imagecreatefromjpeg()
imagecreatetruecolor()
imagecopyresampled()
imagejpeg()
However people are complaining that there CYMK logos are coming up different colours after being uploaded. I know this is because GD is doing a conversion to RGB but i am wondering if there is a way to improve this?
As these are often peoples logos, they rightly get protective over the colours used and want them to be right.
I know there are some good tools to convert single colours online but i want something that can be added to my class file that converts all the CMYK colours in an image to a more accurate version of the CMYK equivalent.
As a quick example, a pic uploaded without conversion and then selected with a colour picker extension in chrome gives me this HEX code: #992A78. Having run it through the above scripts, it converts it to this one: #9000F6;
Anyone got any advice for me? Thanks
GD doesn't support color management at all, which explains the color shift, so there is probably no feasible workaround there. You might want to do some quick tests using ImageMagick, which seems to support various color profiles.

Is there a PHP library for drawing text as a vector outline?

In PHP, it's quite easy to use GD to draw text onto a raster canvas in a certain font (according to a TTF file held on the server), and output it as a PNG or JPEG.
I want to do roughly the same thing, but to draw the text as a vector outline and output it as an SVG.
(I do not want to embed the font itself in the resulting SVG, as the font is not licensed for that.)
Is there any PHP library that provides this sort of functionality?
It's possible to script inkscape to do this.
The following command opens "example.svg" and selects all shapes in the file and converts them to paths, and then saves and closes the file.
inkscape --verb EditSelectAll --verb ObjectToPath --verb FileSave --verb FileClose example.svg
I was able to find CleverSVG trough searching, however I did not try this myself, and I am unsure if it will be able to draw text without forwarding the font.

Using PHP to recreate something similar to VistaPrint / CafePress / Zazzle. Any Ideas?

I am working on a website in which the client wishes to have users upload background images to a printable design, crop to size, add text. Do this to multiple pages then generate a pdf of the 'book'
I am running into the following issues/questions and just need to see where I can start
Are there any PHP developer packages that can do something similar. I have seen jquery crop tools but something also for adding text to an image?
How would I keep the resolution up? If the final cropped with text image needs to be 150dpi, when cropping I am guessing I would have them working on a 72dpi image, then somehow apply the crop and changes to the large image?
If the resolution issue wasn't a big deal I would go about it this way:
Simple image upload
Use jquery to crop photo to correct dimensions
Mess around with gdlibrary and imagettftext() to get the text onto an image (page)
Use something like FPDF to create a pdf from each 'page'
Is this the right way to go about it and any thoughts on the resolution issue. Thank you for any help!
Your primary tool should be ImageMagick. ImageMagick can do the cropping, resizing, scaling, overlay text or graphics, combining images, and apply special effects. A big advantage of using a separate tool instead of PHP's image manipulation tools is that you can do the same transforms in batch through other mechanisms, or even hand the work over to another server to keep the website more responsive. And if you do want to integrate it tightly into the website, you can use the MagickWand For PHP interface.
Cropping does not change DPI, only the dimensions of the image. Scaling, on the other hand, changed both.
You should take a look at Gallery, a GPLed program with some of the functionality you're looking for, and written in PHP.
domPDF is a good tool for converting HTML to a PDF. this way you can use the image they upload as a background image, then put the text over it in any standard HTML tag.
As far as the resolution/dpi issue goes, I'm not sure if there is much you can do outside of changing the size of the image. I would recommend looking into This PHP Library, which has a lot of good tools for manipulating images.
I think with a combination of these tools, you'll be able to create HTML that can make a PDF that's fit to print, and use that.

Categories