PHP ImageMagick png to eps conversion with transparent background - php

I have a png image with transparent background and i tried to convert that to an eps file using convert command of imagemagick,and got eps image with white background.
I want eps image with transparent background.I have a php application for designing images for tshirt printing,So image transparency is must.
Also image quality of output eps image is pretty bad and image size is really big comparing to input size.
I had tried command
convert test2.png -resize 1024x1024 -density 500 -units pixelsperinch -quality 100 -compress none -alpha set -flatten -background none -depth 20 test2_eps.eps
Iam using system function of php to execute this command.
Is there any option to maintain transparency of input image? Is it white by default? How can we improve output eps image quality?

PostScript (and therefore EPS) doesn't have a concept of transparency (with some exceptions), so you can't readily convert an image with an alpha channel to an EPS.
If the 'background' is 100% transparent it is possible to create a similar effect in PostScript using masked images (that's 2 images, where the second is a mask that determines where the 1st image draws). That's a rarely used feature, and requires a level 3 PostScript interpreter. Most EPS export functionality doesn't go above level 2.
As to whether ImageMagick can create such an EPS, I have no clue, but I wouldn't be at all surprised to find it cannot. You may have to use something like Photoshop.
Regarding the image size; PNG is a compressed format, and you have specified
-compress none
So its hardly surprising that the output is larger!
Its essentially impossible to comment on your quality problem, partly because you haven't really said exactly what it is that you see as a problem. 'Quality' is rather vague, perhaps you could post an example.
If your EPS has a thumbnail preview do not be fooled into thinking this is what the EPS contains, its a low resolution bitmap preview only and its there for the benefit of EPS consumers that can't interpret the PostScript content. So that they can preview the result when you place the EPS in the final document.

Related

Save PNG as PNG-8 with Floyd-Steinberg 2 dithering like GIMP in PHP

In GIMP I can save an image for Web with these properties:
PNG-8
256 colors palette
Dither: Floyd-Steinberg / Floyd-Steinberg 2 / positioned
With these options I can reduce upto about 70% of the size of the image file without evident quality loss.
How can I get the same result with PHP?
The resulting image must preserve transparency.
I know almost nothing about image compression, encoding, palette, etc.
Edit: I posted a new question with a PHP script to do that, so I'll close this question or I'll answer it.
PHP wrong result for imagetruecolortopalette with PNG with transparency

why ghost script in detect total ink coverage the result was same value CMYK?(PHP)

I was trying to convert .doc files to pdf files the reference at Convert Word doc, docx and Excel xls, xlsx to PDF with PHP, and successfull to convert to pdf,,, when i detect total ink coverage with ghost script the result fil value for CMYK in same value like,,,
PAGE 1 0.8557 0.8557 0.8557 0.8557 CMYK OK
The correct result is
PAGE 1 0.0000 0.0000 0.0000 1.0000 CMYK OK
because my file contain all black font
`My php script for convert to pdf`
$result = exec('"C:\Program Files (x86)\OpenOffice 4\program\python.exe"
D:\wamp\www\doc_to_pdf\libobasis4.4-pyuno\unoconv -f pdf -o
D:/wamp/www/doc_to_pdf/files/'.$pdf_File_name.'
D:/wamp/www/doc_to_pdf/files/'.$doc_file_name);
my ghost script
-o - -sDEVICE=inkcov E:/fileconverted.pdf
BTW i use openoffice and unoconv
You may think that your file contains black text only, and indeed it probably does in a sense, but....
Because you used a word processor instead of a graphics arts application, the text colour is almost certainly specified in an RGB colour space. So if you asked for 50% green text you wouldn't get 50% Cyan, 50% Yellow, 0% Magenta and 0% Black, what you get is 0% Red, 50% Green and 0% Blue. This is because the operating system, which is after all driving an RGB monitor, works in RGB space.
For black text (R=G=B=0), when you convert that to CMYK it does not become C=M=Y=0, K=1. This is a well known problem with colour space conversion.
So in short, what you see is correct, the problem is with your expectation.
I would imagine that the PDF files you have created specify the colour of the text in RGB as well. When you use the inkcov device this causes Ghostswcript to convert the RGB into CMYK, using the standard PostScript/PDF conversion algorithm. The standard conversion from RGB to CMYK is given on page 476 of the PostScript Language Reference Manual.
There are other ways to deal with this conversion, but its complicated and I would need to know why you want the CMYK ink coverage before making any recommendations.
Of course, since you haven't posted an example file to study, this is all speculation. If you would care to make an example available I will look at it and check.
[after viewing file]
Yep, all the colour is specified in DeviceRGB.
Not only that, but each page defines a transparency group, with a blending space of RGB. So even if the text was drawn in CMYK, it would be converted into RGB for the transparency blending. Yes I know that the file doesn't have any transparent objects, but a lot of not terribly bright PDF producers emit transparency groups even when they don't actually use any transparent content. Anything using Cairo is particularly susceptible to this.
So basically, what Ghostscript's inkcov device is telling you is correct and its a consequence of the fact that your content is in RGB.
Now if you'll tell me why this is a problem, I might be able to help. Though given that presence of the transparency group, that may be difficult.

PHP Convert JPEG or PDF to PNG with transparency

Im trying to convert a PDF or JPG file into a png with specific colors being transparent.
For example. I have a file with white background and black text and would like to convert the white area to be transparent on the png
I have tried using imagemagick :
exec('convert -density 144 ' . $infile.' -transparent "#FFFFFF" ' .$png_file);
and this seems to work at times and not other times for some reason
also the edges of the black come out kind of jagged. Does anyone know of a way to make the edges smoother. or any other function in php to use to create the transparency.
Also the quality needs to be perfect as well as sometimes when the dimensions of the file are small the output png is very low res and i need to keep it at the same dimensions so i cant really use the -density function
You can overcome the jagged edges using the fuzz factor option -fuzz, but as the usage manual explains, the results may or may not fit your needs.
Background removal is also discussed at length in the usage manual, describing several techniques besides using the -transparent option.
Without more information, I don't know why your conversion code works sometimes and not at others, but I don't think you need the -density option for JPG conversion. That might be the problem.

Saving jpg to png increases size [duplicate]

This question already has an answer here:
PHP: imagepng is creating inordinately large files
(1 answer)
Closed 9 years ago.
I use the following code to save any format of image to png :
$crawl_outfile = 'webss_' . uniqid() . '.png';
imagepng(imagecreatefromstring(file_get_contents($src)),$crawl_outfile);
And it increases the size of 290 KB to 1.7 MB.
Cannot understand the reason. Is there any way(parameter) to get smaller image ?
JPEG is a lossy compression format (some detail in the image is lost), where PNG is not. Therefore, the PNG will be larger in file size.
PNG is efficient at compressing some things, like large areas of the same color. JPEG is better at compressing photos.
PNG stands for Portable Network Graphics. It stores pixels precisely and its compression technique works best for pixel drawings and screenshots with large areas of solid colors. For continuous tone images (i.e., photos) where the color changes just slightly between each pixel, it is not able to compress them very much. The handy OptiPNG or PngCrush tools can reduce the size of a PNG file a bit, but the short answer is that you'll never get a PNG photo down to the size of a JPEG.
JPEG stands for Joint Photographic Experts Group. It is designed for continuous tone images and compresses them extremely well. On the other hand, its lossy compression technique loses color detail that is considered too subtle for humans to notice, and it copes badly with sharp edges.
Additionally note that PNG supports transparency, paletted images, and animation, which JPEG doesn't, but JPEG has more complicated metadata support, and a (rarely supported) lossless mode. So the two formats each have their own quirks. To minimize the file size you'll want to choose the format based on the visual characteristics of the image. Basically, use JPEG for photos and PNG for everything else.
I don't know good about this but may be it caused by PNG file that contain information about transparent part .. so it must be bigger
So there's nothing to do if you want change format in same size with smaller filesize
Here is info about PNG
It's about file size over quality. PNG is better at handling large blocks of colour than JPG is

General Image Optimisation for the Web in ImageMagick

I currently do a strait copy() of images that are the correct width/height to go into my site. I was wondering what sort of best practicies in Imagemagick should I be doing to ensure filesize is lowest it can be without loosing quality of the JPEG?
What you can do is that identify the current image quality & size before you do your copy and compression
Example
identify -verbose rose.jpg
Would return all information including
Compression
Quality
Resolution
Depth
File Size
etc ...
To do your own Optimization
Don't just use fixed values .. used the information too calculated possible and ideal compression and size for the image
Example
If an image quality is 70 and 60 is your bench mark .. all you need so do is reduce it by 10% and its it is 100 reduce by 40% .. at all times you would images with the same level of quality
I resize on upload as even if you read a jpg into Imagemagick and save without doing anything it recompresses it.
If you resize and use -resize all EXIF data is kept; using -thumbnail all EXIF data ( including the embeded thumbnail ) apart from the colour profile is stripped. You can also use -strip on its own which will remove all EXIF data and the colour profile.
To keep the quality in jpg use -quality 100 so you could use something like:
convert input.jpg -strip -quality 100 output.jpg

Categories