[SOLVED] create a sheet of labels
- Draoidh
- Posts: 69
- Joined: 2012-07-03T11:29:44-07:00
- Authentication code: 13
- Location: soon to be independent Scotland
[SOLVED] create a sheet of labels
I would like to create a sheet of labels from an image and output it to PDF.
It's easy enough to do with gLabels but I'd be quite keen to create the sheet automagically with ImageMagick. Precise positioning is obviously very important.
Is this a sensible idea? Any views would be welcome.
It's easy enough to do with gLabels but I'd be quite keen to create the sheet automagically with ImageMagick. Precise positioning is obviously very important.
Is this a sensible idea? Any views would be welcome.
Last edited by Draoidh on 2012-12-17T04:04:51-07:00, edited 2 times in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: create a sheet of labels
How about showing us an example of what you want before converting to PDF or the final pdf? And explain a bit more about whether the text labels are all one or how they are separated. Also what version of IM and what platform?
- Draoidh
- Posts: 69
- Joined: 2012-07-03T11:29:44-07:00
- Authentication code: 13
- Location: soon to be independent Scotland
Re: create a sheet of labels
I am using ImageMagick 6.7.7-10 on Debian Linux.
The intended output is a PDF file suitable to print a 7x3 A4 label sheet. The labels are rectangular with rounded edges.
The starting point is a PNG image for ONE label.
This image needs to be tiled (7x3) with the appropriate page margins.
The intended output is a PDF file suitable to print a 7x3 A4 label sheet. The labels are rectangular with rounded edges.
The starting point is a PNG image for ONE label.
This image needs to be tiled (7x3) with the appropriate page margins.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: create a sheet of labels
Without an image, it is hard to know what to tell you. All I can do is suggest you review one or all:
http://www.imagemagick.org/Usage/montage/
http://www.imagemagick.org/Usage/layers/#append
http://www.imagemagick.org/Usage/layers/#layers
http://www.imagemagick.org/Usage/layers/#composite
montage may be the best bet.
http://www.imagemagick.org/Usage/montage/
http://www.imagemagick.org/Usage/layers/#append
http://www.imagemagick.org/Usage/layers/#layers
http://www.imagemagick.org/Usage/layers/#composite
montage may be the best bet.
- Draoidh
- Posts: 69
- Joined: 2012-07-03T11:29:44-07:00
- Authentication code: 13
- Location: soon to be independent Scotland
Re: create a sheet of labels
Here's an image to be printed on each label:
The label sheet specification: 21 labels per A4 sheet
I'd like a print quality of 300dpi.
The label sheet specification: 21 labels per A4 sheet
I'd like a print quality of 300dpi.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: create a sheet of labels
Figure out how to equally divide the A4 sheet into 3 columns of 7 rows (21 cells) and note the upper left corner pixel coordinates for each cell. Then use -flatten with -page to specify where to put the upper left corners of each image. This assumes that your label image in pixels is no bigger than one cell of the 21 cells division of the A4 sheet. If it is, then you have to resize the label image smaller than the cell size. You can set the dpi by using -density.
see
http://www.imagemagick.org/script/comma ... s.php#page
http://www.imagemagick.org/Usage/layers/#flatten
http://www.imagemagick.org/script/comma ... hp#density
see
http://www.imagemagick.org/script/comma ... s.php#page
http://www.imagemagick.org/Usage/layers/#flatten
http://www.imagemagick.org/script/comma ... hp#density
- Draoidh
- Posts: 69
- Joined: 2012-07-03T11:29:44-07:00
- Authentication code: 13
- Location: soon to be independent Scotland
Re: create a sheet of labels
Before I tried anything complicated, I played around with the -page option, but I didn't get to grips with it.
Here I simply tried to create an A4 PDF file with one image on it:
When I open the file with gv, a page size of y673x476 is displayed, not y842x595.
produces a page of size y842x595.
I am not quite sure I understand the -page option. A width of 595dpi for a 21cm wide page equates to 72dpi. Does that mean we specify the page size in terms of 72dpi? Where does the -density setting come in?
Here I simply tried to create an A4 PDF file with one image on it:
Code: Select all
convert label.png -page a4 page.pdf
Code: Select all
convert xc:white -page a4 page.pdf
I am not quite sure I understand the -page option. A width of 595dpi for a 21cm wide page equates to 72dpi. Does that mean we specify the page size in terms of 72dpi? Where does the -density setting come in?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: create a sheet of labels
A better way is to make a montage with the label as is and then trim and resize it. That is probably the easiest approach.
But you may get extra padding on the right or bottom depending upon whether your image has the correct aspect ratio to fit 3x7 times into 495x842 which is the pixel size defined for an A4 page according to -page link
For starters, try equal spacing:
montage label.png -duplicate 20 -tile 3x7 -geometry +5+5 -background white miff:- | convert - -trim +repage -resize 595x842 -background white -extent 595x842 -density 300 result.png
So this produces a result that does not fill the vertical space.
So after measuring and adjusting.
montage label.png -duplicate 20 -tile 3x7 -geometry +5+45 -background white miff:- | convert - -trim +repage -resize 595x842 -background white -extent 595x842 -density 300 result2.png
But you may get extra padding on the right or bottom depending upon whether your image has the correct aspect ratio to fit 3x7 times into 495x842 which is the pixel size defined for an A4 page according to -page link
For starters, try equal spacing:
montage label.png -duplicate 20 -tile 3x7 -geometry +5+5 -background white miff:- | convert - -trim +repage -resize 595x842 -background white -extent 595x842 -density 300 result.png
So this produces a result that does not fill the vertical space.
So after measuring and adjusting.
montage label.png -duplicate 20 -tile 3x7 -geometry +5+45 -background white miff:- | convert - -trim +repage -resize 595x842 -background white -extent 595x842 -density 300 result2.png
- Draoidh
- Posts: 69
- Joined: 2012-07-03T11:29:44-07:00
- Authentication code: 13
- Location: soon to be independent Scotland
Re: create a sheet of labels
Fred, thank you for your help with this.
A small correction:
convert - -trim +repage -resize 2480x3508 -background white -extent 2480x3508 -density 300 result.png
595x842 are the correct values at 72dpi (i.e. for -density 72). If you want to print an A4 sheet at 300dpi, you need to create a picture with a size of 2480x3508. 1240x1754 numbers for 150dpi.
It is obviously possible to create a 3x8 label image and a PDF from that. However, the PDF file created with gLabels via print to file is very much smaller and better quality (noticable difference when zoomed in at 400%).
For a 460x340 white-on-red input PNG I get PDF files of 1MB and 470KB respectively. The gLabels PDF even zips down to 25KB.
For a 4-color input PNG I get PDF files of 1.5MB and 700KB respectively (neither of which reduce by zipping).
I presume the PDF file created by gLabels only embeds the image once.
A small correction:
convert - -trim +repage -resize 2480x3508 -background white -extent 2480x3508 -density 300 result.png
595x842 are the correct values at 72dpi (i.e. for -density 72). If you want to print an A4 sheet at 300dpi, you need to create a picture with a size of 2480x3508. 1240x1754 numbers for 150dpi.
It is obviously possible to create a 3x8 label image and a PDF from that. However, the PDF file created with gLabels via print to file is very much smaller and better quality (noticable difference when zoomed in at 400%).
For a 460x340 white-on-red input PNG I get PDF files of 1MB and 470KB respectively. The gLabels PDF even zips down to 25KB.
For a 4-color input PNG I get PDF files of 1.5MB and 700KB respectively (neither of which reduce by zipping).
I presume the PDF file created by gLabels only embeds the image once.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: create a sheet of labels
Sorry I cannot tell you how to optimize PDFs. I am not that knowledgeable. I can only refer you to http://www.imagemagick.org/Usage/formats/#ps. Perhaps someone else can help or perhaps you need to output to png and then use some other convert to pdf.
The only other suggestion is to use -type palette before output to PDF to reduce the image size or if converting to PNG first use PNG8:output.png
The only other suggestion is to use -type palette before output to PDF to reduce the image size or if converting to PNG first use PNG8:output.png
- Draoidh
- Posts: 69
- Joined: 2012-07-03T11:29:44-07:00
- Authentication code: 13
- Location: soon to be independent Scotland
Re: create a sheet of labels
I first created the label sheet as PNG, then converted this to PDF. If I go straight to PDF, the file size is double as big.
I don't know enough about PDF/PS formats myself but if I am correct in assuming that gLabels creates the print output (PDF) by embedding the image only once, then this will always give me a smaller file.
I don't want to reduce image quality. So I might just have to do the job manually.
I suspect that IM may not be the sensible tool for this job.
I don't know enough about PDF/PS formats myself but if I am correct in assuming that gLabels creates the print output (PDF) by embedding the image only once, then this will always give me a smaller file.
I don't want to reduce image quality. So I might just have to do the job manually.
I suspect that IM may not be the sensible tool for this job.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: create a sheet of labels
I am no expert, but I do not see how it could do that.I don't know enough about PDF/PS formats myself but if I am correct in assuming that gLabels creates the print output (PDF) by embedding the image only once, then this will always give me a smaller file.
- Draoidh
- Posts: 69
- Joined: 2012-07-03T11:29:44-07:00
- Authentication code: 13
- Location: soon to be independent Scotland
Re: create a sheet of labels
I was wrong in assuming that gLabels embeds the image only once. However, it is possible to create PDF/PostScript files with the image embedded once and drawn x times.fmw42 wrote:I am no expert, but I do not see how it could do that.I don't know enough about PDF/PS formats myself but if I am correct in assuming that gLabels creates the print output (PDF) by embedding the image only once, then this will always give me a smaller file.
Here are the results of my tests:
input file: a 3-colour PNG file (solid red/green/black) 700x500 pixels. 72KB
intended output file: 8x3 PDF output @ 300dpi
I used three different programs: ImageMagick 6.7.7, gLabels, gle (Graphics Layout Engine)
The following list details the sizes of the resultant output file:
- create PNG with ImageMagick: 5.5MB
- create PDF from above PNG using convert: 1.5MB
- create PDF with ImageMagick: 32.4MB
- create PDF with gLabels: 1.23MB
- create PDF with gle: 72.5KB
- ImageMagick: both PDF files contain one image of 2480x3508
- gLabels: the PDF file contains 24 images of 700x500
- gle: the PDF file contains one images of 700x500 (and code drawing it 24 times)
This is not a criticism of ImageMagick! It's just a case of finding the right tool for the job.
Code used to create PDF via PNG with ImageMagick:
Code: Select all
montage input.png -duplicate 23 -tile 3x8 -geometry +5+5 -background white miff:- | convert - -trim +repage -resize 2480x3508 -background white -extent 2480x3508 -density 300 result.png
convert result.png result.pdf
Code: Select all
montage input.png -duplicate 23 -tile 3x8 -geometry +5+5 -background white miff:- | convert - -trim +repage -resize 2480x3508 -background white -extent 2480x3508 -density 300 result.pdf