TCPDF - CMYK images in PDF appear "mainly black" in Illustrator - php

I have a problem when opening with Illustrator a PDF generated with TCPDF that embeds a CMYK image (jpg).
The PDF looks just fine when opening it on a web browser or with Acrobat Reader.
But when trying to open it with Illustrator : although, the file is under the expected CMYK color mode, the rendered colors are not correct at all and looks "mainly black".
Basically :
I create and export a simple CMYK JPG image with Illustrator (see image)
NB : embedding the color profile or not doesn't change the result.
I create the PDF and insert the CMYK jpg image using TCPDF :
$this->pdf->Image("image.jpg", $x, $y, $w, $h, '', '', '', false, $dpi);
The result looks nice on a web browser or in Acrobat Reader : image
But the render is completely wrong when opening the PDF with Illustrator : image of bad render
I have tried the two ways suggested here :
https://github.com/tecnickcom/TCPDF/issues/192
But nothing is working.
I would like to open the PDF with Illustrator to be able to make some manual changes in some cases.
Has anyone a clue about this ?

Related

How to add watermark Image using MPDF in codeigniter

here is the pdf image
I want to add this kind of background image to my PDF using MPDF. But also i want to reduce the background image opacity.
Try this-
$mpdf->SetWatermarkImage(
'assets/dist/img/ExampleLogo1.png',
0.3, // this for transparency
array(x,y), // Alignment
);

CMYK Mode after generating a PDF of images in DOMPDF Laravel

I am working on HTML to PDF generation, i am using laravel with DOMPDF library, I have 3 different images, i have that image through css and html, its working fine, but after when we downloading the file and opening into Photoshop its show RGB mode
I want it to show cmyk Mode.
This is the output file of my pdf
My PDF download code after rendering the html
$customPaper = array(0,0,4500,2950);
$pdf->setOptions(['dpi'=>300]);
$pdf->loadHTML($html)->setPaper($customPaper)->setWarnings(false)->save($filename.'.pdf');
return $pdf->stream();

png with transparency and png-derived blob are rendering black on canvas element instead of transparent

I am letting users preview images using URL.createObjectURL() (which represents the image as a blob). This has worked great, but now I am using the plugin jCrop to let users crop said images and I have encountered a minor issue.
jCrop has worked fine for blobs derived from jpg files and png files w/o transparency, but blobs derived from png files with transparency are rendering transparent pixels (on the canvas) as black (the same effect was happening with these images when resized and uploaded to the backend (php) but this was corrected using imagealphablending()).
jCrop is called as followed:
jQuery(function($) {
$("#myImageContainer").Jcrop({
onChange: myFunction
}, function () {
jcrop_api = this;
});
});
The "black" images on canvas are uploaded and saved properly with transparency, so this is a front end effect only. Additionally, the same effect is observed when the source png is used to preview instead of the png-derived blob. Is their any way to correct for this effect on the canvas instead of the backend?
UPDATE: The transparent image is black from the start...I am assuming the author of the plugin set the canvas background to be black. I will try and change this.

Imagick can't write SVG files

I use Imagick to open an image, resize it, set an image format (if it's needed) and write in another folder the result. It works with ICO and PNG, but can't write SVG files, saying that
ImagickException: Unable to write the file: C:\Sites\devdesktop\test\sites\default\files\tempimages\abstract-spiral-striped-background-100.svg in Imagick->writeimage() (line 44 of C:\Sites\devdesktop\test\sites\all\modules\testmodule\testmodule.module).
It was an error message from Drupal 7.
Here is my code:
$file = file_load($form_state['values']['fid']);
$image = new Imagick(drupal_realpath($file->uri));
$image->setImageFormat($type[$type_num]);
$image->resizeImage($size[$size_num], $size[$size_num], Imagick::FILTER_UNDEFINED, 1);
$destination = 'public://tempimages/'.substr($file->filename, 0, -4).'-'.$size[$size_num].'.'.$type[$type_num];
$image->writeImage(drupal_realpath($destination)); //<---problem
drupal_goto(base_path().'/sites/default/files/tempimages/'.substr($file->filename, 0, -4).'-'.$size[$size_num].'.'.$type[$type_num]);
This code snippet works perfectly with ICO and PNG, but don't write a file in SVG format except a little peace of code
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="200" height="200">
<g style="</svg>
Why so?
SVG isn't an image in the same way that JPG or PNG are.
It's just an xml with plotted points in most cases, and is typically void of dimension and resolution.
The width and height of 200 are just the size in px at which it was saved. So you should never need to 'resize' an svg, as it will scale infinitely.
If you put an SVG in an img tag and define the dimensions, like:
<img src="myawesome.svg" width="500" height="500" />
Even though it's defined in the SVG as having a dimensions of 200, it should scale larger or smaller with no change in the quality of appearance.
Because of this complete difference in structure, it will not follow the same rules in some cases as jpg or png will as they are rendered images.
If this is being done in Drupal; make an exception for SVG that just stores the file without resizing, and add the dimensions where ever it is printed for all images. It won't hurt the rendered images, and it should show the SVG as the same size as them.
TL;DR SVG is an xml file, not really an image, resizing it is pointless since it carries no real resolution or size and can scale infinitely. They only appear to be similar since they are both visual elements. Make an exception for SVG so it just stores the file, and when either the rendered images or the SVG is printed, add the resized dimensions to the img output.

CROP IMAGE IN FPDF is possible?

May i crop images in FPDF ?
i have try this one Cropping images in CodeIgniter for FPDF output but does not work
You can use clipping areas: http://www.fpdf.org/en/script/script78.php
With this extension you can define your visible area and output your image like this:
$pdf->ClippingRect($x, $y, $w, $h);
$pdf->Image($imageFile, $x - $imgOffsetX, $y - $imgOffsetY);
$pdf->UnsetClipping();
The whole image will be included in the pdf. If size matters, cropping the image file first can be the better way.
Sorry, you can not crop an image in FPDF. You must first crop the image before using it to create a PDF using FPDF. I can recommend doing this manually, or programmatically via ImageMagick. Then once you have your cropped jpg, gif or png, call Image.
$pdf->Image('croppedImage.png');

Categories