Is possible to check if a PNG image has transparent background? - resize

I'm using a crop & resize function for images, but I need to let it crop/resize ONLY png files WITH transparent backgrounds, at least 1 pixel in the image should be transparent for the image to be accepted.
Is possible to check if a PNG image has transparent background/pixels?
I'm using PHP and GD libraries.
EDIT: Ok, I've figured out how to do this on PHP with GD libraries. Look how clean it looks! :)
<?php
$im = imagecreatefrompng("php.png");
$rgba = imagecolorat($im,1,1);
$alpha = ($rgba & 0x7F000000) >> 24;
var_dump($alpha);
?>
Any ideas how to do an array for the x/y coordenates to check all the image pixels looking for at least 1 pixel = $alpha = 127?

You can call out to imagemagick for it:
https://www.imagemagick.org/discourse-server/viewtopic.php?t=18596
convert my_image.png -format "%[opaque]" info:
False

Well you can certainly run through all the pixels and check to see if any of them have an alpha that is not 255. What language and libraries are you using?

One way to handle this in Imagemagick is to check the mean value of the alpha channel. If 1, then it is opaque. Otherwise, the alpha channel has some transparency either somewhere or partial transparency.
convert logo: -channel a -separate -format "%[fx:mean]" info:
1
convert logo: -transparent white -format "%[fx:mean]" info:
0.894907
So you can do:
convert image -format "%[fx:mean==1?1:0]" info:
If the return value is 1, then it is fully opaque. If the return value is 0, then there is some transparency somewhere.

Related

converting a pdf page to an image using GraphicsMagick

How do I convert only page 2 of a pdf file to a jpg image file, using GraphicsMagick command line prompt?
What option can I use in the gm.exe convert command?
gm.exe convert testing.pdf testing.jpg
Add the page number (starting from zero) in square brackets after the PDF filename:
gm.exe convert testing.pdf[1] testing.jpg
By the way, you can use the same indexing technique for accessing specific frames of a GIF animation, or layers of multi-layer/directory TIFFs.
use the blow command, will get high quality png with white background.
magick convert -density 300 -quality 100% -background white -alpha remove -alpha off ./646.04.pdf ./x.png

Getting colour palette from a photoshop file

I have a photoshop file with several layers (all shapes, no bitmaps). Is there any automatic way I could extract the colours from all these shapes into a palette? Any advice would be great!
You can do that from the commandline with ImageMagick if you want to. It is installed on most Linux distros and available for Mac OSX and Windows.
So, if I start with this Photoshop file:
and do this:
convert image.psd -flatten -unique-colors palette.png
I get this (I have enlarged it 5000% so you can see it):
Or, if you want it as text:
convert image.psd -flatten -unique-colors txt:
# ImageMagick pixel enumeration: 5,1,255,srgb
0,0: (0,0,0) #000000 black
1,0: (255,0,0) #FF0000 red
2,0: (0,255,0) #00FF00 lime
3,0: (0,0,255) #0000FF blue
4,0: (255,255,255) #FFFFFF white
Without knowing your source image, I can't say for sure, but as far as I know, the only real palette exists with bitmap images of indexed color.
So you'd change your color mode to "indexed", giving you a 256 color palette ready for export.
Depending on your use case that may already be enough – you can also try to export a file with as few colors as possible (saving a GIF), giving you the opportunity to filter down on the most used colors in your image.

Apply color band to TIFF in the PDF

• Background :
We are developing AFP to PDF tool. It involves conversion of AFP (Advanced Function Processing) file to PDF.
• Detailed Problem statement :
We have AFP file with embedded TIFF Image. The image object is described in Function Set 45, represented somewhat like this -
Image Content
Begin Tile
Image Encoding Parameter – TIFF LZW
Begin Transparency Mask
Image Encoding Parameter – G4MMR
Image Data Elements
End Transparency Mask
Image Data Elements (IDE Size 32) – 4 bands: CMYK
End Tile
End Image Content
We want to write this tiled image to PDF either using Java /iText API.
As of now, we can write G4MMR image. But, we are not able to apply CMYK color band data (Blue Color) to this image.
• Solution tried :
The code to write G4MMR image goes as follows –
ByteArrayOutputStream decode = saveAsTIFF(<width>,<height>,<imageByteData>);
RandomAccessFileOrArray ra=new RandomAccessFileOrArray(saveAsTIFF.toByteArray());
int pages = TiffImage.getNumberOfPages(ra);
for(int i1 = 1; i1 <= pages; i1++){
img1 = TiffImage.getTiffImage(ra, i1);
}
img1.scaleAbsolute(256, 75);
document.add(img1);
saveAsTIFF method is given here –
http://www.jpedal.org/PDFblog/2011/08/ccitt-encoding-in-pdf-files-converting-pdf-ccitt-data-into-a-tiff/
As mentioned, we are not able to apply CMYK 4 band image color data to this G4MMR image.
• Technology stack with versions of each component :
1. JDK 1.6
2. itextpdf-5.1
-- Umesh Pathak
The AFP resource you're showing is a TIFF CMYK image compressed with LZW. This image is also using a "transparency mask" which is compressed with G4MMR ( a slightly different encoding than the traditional Fax style G4).
So the image data is already using the CMYK colorspace, each band (C,M,Y,K) is compressed alone using simple LZW encoding and should not be too difficult to extract and store as a basic TIFF CMYK file. You'll also have to convert the transparency mask to G4 or raw data to use it in a pdf file to maks the CMYK image.
If you want better PDF output control, I suggest you take a look at pdflib
You need to add a CMYK colorspace to your image before adding it to the PDF file. However I am afraid this might not be fully supported in iText. A workaround for you could be to convert your image into the default RGB colorspace before adding it to the PDF file, however this will probably imply some quality loss for your image.

Imagemagick unwanted black background on rotated transparent images

I have a website that generates polaroid-like images stacked on eachother at different angles.
Up until now everything worked well, but now i've started getting some black background around my transparent .png's.
You can see the problem here. The images in the last album are all messed up.
I'm using imagemagick (6.5.4.7-3.fc12).
my commands look something like this:
the first one is contained whitin a foreach and generates a bunch of pngs rotated at different angles
convert '{$sf}' -auto-orient -thumbnail 120x120 -gravity center -bordercolor snow -background black -polaroid {$angle} {$i}.png
the second command takes the previously generated images and stacks them toghater
convert '*.png' -background transparent -alpha on -gravity center -layers merge -extent 190x190 +repage -thumbnail 115x115 -gravity center -extent 120x120 'result.png'
As far as I got with the debuging, the black background is already present in the images generated with the first command and they only appear when I rotate the images. If I only use -polaroid 0 instead of the +polaroid, then the resulting images are ok.
My guess is that the problem is not with the code itself, but rather ImageMagick or something else got upgraded on my server and that started this whole mess.
I also tried all kinds of combinations with setting -alpha and everything else i could find in the imagemagick docs that is even just slightly related to transparency, but nothing seems to work.
After all sorts of testing I finally got to the conclusion that the problem was not with my convert commands.
The solution to my problem was to reinstall/update ImageMagick.
//It romove the unwanted black/white background and make it transparent backgraund.
ImageInfo info1 = new ImageInfo(
"/opt/apache-tomcat-6.0.18/webapps/newcpclient_branch/upload/sample/ATT00003.jpg");
MagickImage blankImage = new MagickImage(info1);
**blankImage.setBackgroundColor(PixelPacket.queryColorDatabase("#FFFF8800"));**
blankImage = blankImage.rotateImage(250.0);
blankImage.setFileName("/opt/apache-tomcat-6.0.18/webapps/newcpclient_branch/upload/sample/transparent.png");
blankImage.writeImage(info1);
You have -background set to 'black' in your first line. That means you don't get transparency. Does it work if you set it to 'none'?
Edit:
import os
import random as ra
for i in range(10):
image = 'convert C:/image.png -auto-orient -thumbnail 120x120 -gravity center -bordercolor snow -background none -polaroid '+str(ra.uniform(0,360))+' C:/test/image_polaroid_'+str(i)+'.png'
os.system(image)
image = 'convert -size 500x500 xc:transparent C:/test/result.png'
os.system(image)
for i in range(10):
image = 'composite -gravity center C:/test/image_polaroid_'+str(i)+'.png C:/test/result.png C:/test/result.png'
os.system(image)
Edit 2:
import os
import random as ra
for i in range(10):
image = 'convert C:/image.png -background none -polaroid 0 C:/test/image_polaroid_'+str(i)+'.png'
os.system(image)
image = 'mogrify -rotate '+str(ra.randint(0,360))+' -background none C:/test/image_polaroid_'+str(i)+'.png'
os.system(image)

Convert PDF to image with high resolution

I'm trying to use the command line program convert to take a PDF into an image (JPEG or PNG). Here is one of the PDFs that I'm trying to convert.
I want the program to trim off the excess white-space and return a high enough quality image that the superscripts can be read with ease.
This is my current best attempt. As you can see, the trimming works fine, I just need to sharpen up the resolution quite a bit. This is the command I'm using:
convert -trim 24.pdf -resize 500% -quality 100 -sharpen 0x1.0 24-11.jpg
I've tried to make the following conscious decisions:
resize it larger (has no effect on the resolution)
make the quality as high as possible
use the -sharpen (I've tried a range of values)
Any suggestions please on getting the resolution of the image in the final PNG/JPEG higher would be greatly appreciated!
It appears that the following works:
convert \
-verbose \
-density 150 \
-trim \
test.pdf \
-quality 100 \
-flatten \
-sharpen 0x1.0 \
24-18.jpg
It results in the left image. Compare this to the result of my original command (the image on the right):
(To really see and appreciate the differences between the two, right-click on each and select "Open Image in New Tab...".)
Also keep the following facts in mind:
The worse, blurry image on the right has a file size of 1.941.702 Bytes (1.85 MByte).
Its resolution is 3060x3960 pixels, using 16-bit RGB color space.
The better, sharp image on the left has a file size of 337.879 Bytes (330 kByte).
Its resolution is 758x996 pixels, using 8-bit Gray color space.
So, no need to resize; add the -density flag. The density value 150 is weird -- trying a range of values results in a worse looking image in both directions!
Personally I like this.
convert -density 300 -trim test.pdf -quality 100 test.jpg
It's a little over twice the file size, but it looks better to me.
-density 300 sets the dpi that the PDF is rendered at.
-trim removes any edge pixels that are the same color as the corner pixels.
-quality 100 sets the JPEG compression quality to the highest quality.
Things like -sharpen don't work well with text because they undo things your font rendering system did to make it more legible.
If you actually want it blown up use resize here and possibly a larger dpi value of something like targetDPI * scalingFactor That will render the PDF at the resolution/size you intend.
Descriptions of the parameters on imagemagick.org are here
I use pdftoppm on the command line to get the initial image, typically with a resolution of 300dpi, so pdftoppm -r 300, then use convert to do the trimming and PNG conversion.
I really haven't had good success with convert [update May 2020: actually: it pretty much never works for me], but I've had EXCELLENT success with pdftoppm. Here's a couple examples of producing high-quality images from a PDF:
[Produces ~25 MB-sized files per pg] Output uncompressed .tif file format at 300 DPI into a folder called "images", with files being named pg-1.tif, pg-2.tif, pg-3.tif, etc:
mkdir -p images && pdftoppm -tiff -r 300 mypdf.pdf images/pg
[Produces ~1MB-sized files per pg] Output in .jpg format at 300 DPI:
mkdir -p images && pdftoppm -jpeg -r 300 mypdf.pdf images/pg
[Produces ~2MB-sized files per pg] Output in .jpg format at highest quality (least compression) and still at 300 DPI:
mkdir -p images && pdftoppm -jpeg -jpegopt quality=100 -r 300 mypdf.pdf images/pg
For more explanations, options, and examples, see my full answer here:
https://askubuntu.com/questions/150100/extracting-embedded-images-from-a-pdf/1187844#1187844.
Related:
[How to turn a PDF into a searchable PDF w/pdf2searchablepdf] https://askubuntu.com/questions/473843/how-to-turn-a-pdf-into-a-text-searchable-pdf/1187881#1187881
Cross-linked:
How to convert a PDF into JPG with command line in Linux?
https://unix.stackexchange.com/questions/11835/pdf-to-jpg-without-quality-loss-gscan2pdf/585574#585574
normally I extract the embedded image with 'pdfimages' at the native resolution, then use ImageMagick's convert to the needed format:
$ pdfimages -list fileName.pdf
$ pdfimages fileName.pdf fileName # save in .ppm format
$ convert fileName-000.ppm fileName-000.png
this generate the best and smallest result file.
Note: For lossy JPG embedded images, you had to use -j:
$ pdfimages -j fileName.pdf fileName # save in .jpg format
With recent "poppler-util" (0.50+, 2016) you can use -all that save lossy as jpg and lossless as png, so a simple:
$ pdfimages -all fileName.pdf fileName
extract always the best possible quality content from PDF.
On little provided Win platform you had to download a recent (0.68, 2018) 'poppler-util' binary from:
http://blog.alivate.com.au/poppler-windows/
In ImageMagick, you can do "supersampling". You specify a large density and then resize down as much as desired for the final output size. For example with your image:
convert -density 600 test.pdf -background white -flatten -resize 25% test.png
Download the image to view at full resolution for comparison..
I do not recommend saving to JPG if you are expecting to do further processing.
If you want the output to be the same size as the input, then resize to the inverse of the ratio of your density to 72. For example, -density 288 and -resize 25%. 288=4*72 and 25%=1/4
The larger the density the better the resulting quality, but it will take longer to process.
I have found it both faster and more stable when batch-processing large PDFs into PNGs and JPGs to use the underlying gs (aka Ghostscript) command that convert uses.
You can see the command in the output of convert -verbose and there are a few more tweaks possible there (YMMV) that are difficult / impossible to access directly via convert.
However, it would be harder to do your trimming and sharpening using gs, so, as I said, YMMV!
It also gives you good results:
exec("convert -geometry 1600x1600 -density 200x200 -quality 100 test.pdf test_image.jpg");
Linux user here: I tried the convert command-line utility (for PDF to PNG) and I was not happy with the results. I found this to be easier, with a better result:
extract the pdf page(s) with pdftk
e.g.: pdftk file.pdf cat 3 output page3.pdf
open (import) that pdf with GIMP
important: change the import Resolution from 100 to 300 or 600 pixel/in
in GIMP export as PNG (change file extension to .png)
Edit:
Added picture, as requested in the Comments. Convert command used:
convert -density 300 -trim struct2vec.pdf -quality 100 struct2vec.png
GIMP : imported at 300 dpi (px/in); exported as PNG compression level 3.
I have not used GIMP on the command line (re: my comment, below).
For Windows (tested on W11):
magick.exe -verbose -density 150 "input.pdf" -quality 100 -sharpen 0x1.0 output.jpg
You need install:
ImageMagick https://imagemagick.org/index.php
ghostscript
https://www.ghostscript.com/releases/gsdnld.html
Additional info:
Watch for using -flatten parameter since it can produce only first page as image
Use -scene 1 parameter to start at index 1 with images names
convert command mentioned in question has been deprecated in favor to magick
One more suggestion is that you can use GIMP.
Just load the PDF file in GIMP->save as .xcf and then you can do whatever you want to the image.
I have used pdf2image. A simple python library that works like charm.
First install poppler on non linux machine. You can just download the zip. Unzip in Program Files and add bin to Machine Path.
After that you can use pdf2image in python class like this:
from pdf2image import convert_from_path, convert_from_bytes
images_from_path = convert_from_path(
inputfile,
output_folder=outputpath,
grayscale=True, fmt='jpeg')
I am not good with python but was able to make exe of it.
Later you may use the exe with file input and output parameter. I have used it in C# and things are working fine.
Image quality is good. OCR works fine.
Edited:
Here is my another finding, You don't need to install Poppler for conversion.
Just make your converter.exe from Python and place it in binary bin folder of Poppler window.
I suppose it will work on azure aswell.
PNG file you attached looks really blurred. In case if you need to use additional post-processing for each image you generated as PDF preview, you will decrease performance of your solution.
2JPEG can convert PDF file you attached to a nice sharpen JPG and crop empty margins in one call:
2jpeg.exe -src "C:\In\*.*" -dst "C:\Out" -oper Crop method:autocrop
I use icepdf an open source java pdf engine. Check the office demo.
package image2pdf;
import org.icepdf.core.exceptions.PDFException;
import org.icepdf.core.exceptions.PDFSecurityException;
import org.icepdf.core.pobjects.Document;
import org.icepdf.core.pobjects.Page;
import org.icepdf.core.util.GraphicsRenderingHints;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
public class pdf2image {
public static void main(String[] args) {
Document document = new Document();
try {
document.setFile("C:\\Users\\Dell\\Desktop\\test.pdf");
} catch (PDFException ex) {
System.out.println("Error parsing PDF document " + ex);
} catch (PDFSecurityException ex) {
System.out.println("Error encryption not supported " + ex);
} catch (FileNotFoundException ex) {
System.out.println("Error file not found " + ex);
} catch (IOException ex) {
System.out.println("Error IOException " + ex);
}
// save page captures to file.
float scale = 1.0f;
float rotation = 0f;
// Paint each pages content to an image and
// write the image to file
for (int i = 0; i < document.getNumberOfPages(); i++) {
try {
BufferedImage image = (BufferedImage) document.getPageImage(
i, GraphicsRenderingHints.PRINT, Page.BOUNDARY_CROPBOX, rotation, scale);
RenderedImage rendImage = image;
try {
System.out.println(" capturing page " + i);
File file = new File("C:\\Users\\Dell\\Desktop\\test_imageCapture1_" + i + ".png");
ImageIO.write(rendImage, "png", file);
} catch (IOException e) {
e.printStackTrace();
}
image.flush();
}catch(Exception e){
e.printStackTrace();
}
}
// clean up resources
document.dispose();
}
}
I've also tried imagemagick and pdftoppm, both pdftoppm and icepdf has a high resolution than imagemagick.
Please take note before down voting, this solution is for Gimp using a graphical interface, and not for ImageMagick using a command line, but it worked perfectly fine for me as an alternative, and that is why I found it needful to share here.
Follow these simple steps to extract images in any format from PDF documents
Download GIMP Image Manipulation Program
Open the Program after installation
Open the PDF document that you want to extract Images
Select only the pages of the PDF document that you would want to extract images from.
N/B: If you need only the cover images, select only the first page.
Click open after selecting the pages that you want to extract images from
Click on File menu when GIMP when the pages open
Select Export as in the File menu
Select your preferred file type by extension (say png) below the dialog box that pops up.
Click on Export to export your image to your desired location.
You can then check your file explorer for the exported image.
That's all.
I hope this helps
get Image from Pdf in iOS Swift Best solution
func imageFromPdf(pdfUrl : URL,atIndex index : Int, closure:#escaping((UIImage)->Void)){
autoreleasepool {
// Instantiate a `CGPDFDocument` from the PDF file's URL.
guard let document = PDFDocument(url: pdfUrl) else { return }
// Get the first page of the PDF document.
guard let page = document.page(at: index) else { return }
// Fetch the page rect for the page we want to render.
let pageRect = page.bounds(for: .mediaBox)
let renderer = UIGraphicsImageRenderer(size: pageRect.size)
let img = renderer.image { ctx in
// Set and fill the background color.
UIColor.white.set()
ctx.fill(CGRect(x: 0, y: 0, width: pageRect.width, height: pageRect.height))
// Translate the context so that we only draw the `cropRect`.
ctx.cgContext.translateBy(x: -pageRect.origin.x, y: pageRect.size.height - pageRect.origin.y)
// Flip the context vertically because the Core Graphics coordinate system starts from the bottom.
ctx.cgContext.scaleBy(x: 1.0, y: -1.0)
// Draw the PDF page.
page.draw(with: .mediaBox, to: ctx.cgContext)
}
closure(img)
}
}
//Usage
let pdfUrl = URL(fileURLWithPath: "PDF URL")
self.imageFromPdf2(pdfUrl: pdfUrl, atIndex: 0) { imageIS in
}
Many answers here concentrate on using magick (or its dependency GhostScript) as set by the OP question, with a few suggesting Gimp as an alternative, without describing why some settings may work best for different cases.
Taking the OP "sample" the requirement is a crisp trimmed image as small as possible yet retaining good readability. and here the result is 96 dpi in 58 KB (a very small increase on the vector source 54 KB) yet retains a good image even zoomed in. compare that with 72 dpi (226 KB) in the accepted answer image above.
The key point is any image processor can be scripted to batch run from the command line using a profile as input, so here IrfanView (with or without GS) is set to auto crop the pdf page(s) and output at a default 96 dpi to PNG using only 4 BitPerPixel colour for 16 shades of greys.
The size could be further reduced by dropping resolution to 72 but 96 is an optimal setting for PNG screen display.
Use this commandline:
convert -geometry 3600x3600 -density 300x300 -quality 100 TEAM\ 4.pdf team4.png
This should correctly convert the file as you've asked for.
The following python script will work on any Mac (Snow Leopard and upward). It can be used on the command line with successive PDF files as arguments, or you can put in into a Run Shell Script action in Automator, and make a Service (Quick Action in Mojave).
You can set the resolution of the output image in the script.
The script and a Quick Action can be downloaded from github.
#!/usr/bin/python
# coding: utf-8
import os, sys
import Quartz as Quartz
from LaunchServices import (kUTTypeJPEG, kUTTypeTIFF, kUTTypePNG, kCFAllocatorDefault)
resolution = 300.0 #dpi
scale = resolution/72.0
cs = Quartz.CGColorSpaceCreateWithName(Quartz.kCGColorSpaceSRGB)
whiteColor = Quartz.CGColorCreate(cs, (1, 1, 1, 1))
# Options: kCGImageAlphaNoneSkipLast (no trans), kCGImageAlphaPremultipliedLast
transparency = Quartz.kCGImageAlphaNoneSkipLast
#Save image to file
def writeImage (image, url, type, options):
destination = Quartz.CGImageDestinationCreateWithURL(url, type, 1, None)
Quartz.CGImageDestinationAddImage(destination, image, options)
Quartz.CGImageDestinationFinalize(destination)
return
def getFilename(filepath):
i=0
newName = filepath
while os.path.exists(newName):
i += 1
newName = filepath + " %02d"%i
return newName
if __name__ == '__main__':
for filename in sys.argv[1:]:
pdf = Quartz.CGPDFDocumentCreateWithProvider(Quartz.CGDataProviderCreateWithFilename(filename))
numPages = Quartz.CGPDFDocumentGetNumberOfPages(pdf)
shortName = os.path.splitext(filename)[0]
prefix = os.path.splitext(os.path.basename(filename))[0]
folderName = getFilename(shortName)
try:
os.mkdir(folderName)
except:
print "Can't create directory '%s'"%(folderName)
sys.exit()
# For each page, create a file
for i in range (1, numPages+1):
page = Quartz.CGPDFDocumentGetPage(pdf, i)
if page:
#Get mediabox
mediaBox = Quartz.CGPDFPageGetBoxRect(page, Quartz.kCGPDFMediaBox)
x = Quartz.CGRectGetWidth(mediaBox)
y = Quartz.CGRectGetHeight(mediaBox)
x *= scale
y *= scale
r = Quartz.CGRectMake(0,0,x, y)
# Create a Bitmap Context, draw a white background and add the PDF
writeContext = Quartz.CGBitmapContextCreate(None, int(x), int(y), 8, 0, cs, transparency)
Quartz.CGContextSaveGState (writeContext)
Quartz.CGContextScaleCTM(writeContext, scale,scale)
Quartz.CGContextSetFillColorWithColor(writeContext, whiteColor)
Quartz.CGContextFillRect(writeContext, r)
Quartz.CGContextDrawPDFPage(writeContext, page)
Quartz.CGContextRestoreGState(writeContext)
# Convert to an "Image"
image = Quartz.CGBitmapContextCreateImage(writeContext)
# Create unique filename per page
outFile = folderName +"/" + prefix + " %03d.png"%i
url = Quartz.CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, outFile, len(outFile), False)
# kUTTypeJPEG, kUTTypeTIFF, kUTTypePNG
type = kUTTypePNG
# See the full range of image properties on Apple's developer pages.
options = {
Quartz.kCGImagePropertyDPIHeight: resolution,
Quartz.kCGImagePropertyDPIWidth: resolution
}
writeImage (image, url, type, options)
del page
You can do it in LibreOffice Draw (which is usually preinstalled in Ubuntu):
Open PDF file in LibreOffice Draw.
Scroll to the page you need.
Make sure text/image elements are placed correctly. If not, you can adjust/edit them on the page.
Top menu: File > Export...
Select the image format you need in the bottom-right menu. I recommend PNG.
Name your file and click Save.
Options window will appear, so you can adjust resolution and size.
Click OK, and you are done.
convert -density 300 * airbnb.pdf
Looked perfect to me
It's actually pretty easy to do with Preview on a mac. All you have to do is open the file in Preview and save-as (or export) a png or jpeg but make sure that you use at least 300 dpi at the bottom of the window to get a high quality image.
this works for creating a single file from multiple PDF's and images files:
php exec('convert -density 300 -trim "/path/to/input_filename_1.png" "/path/to/input_filename_2.pdf" "/path/to/input_filename_3.png" -quality 100 "/path/to/output_filename_0.pdf"');
WHERE:
-density 300 = dpi
-trim = something about transparancy - makes edges look smooth, it seems
-quality 100 = quality vs compression (100 % quality)
-flatten ... for multi page, do not use "flatten"