Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

psconvert.rst 19 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
  1. .. index:: ! psconvert
  2. .. include:: module_core_purpose.rst_
  3. *********
  4. psconvert
  5. *********
  6. |psconvert_purpose|
  7. Synopsis
  8. --------
  9. .. include:: common_SYN_OPTs.rst_
  10. **gmt psconvert** *psfile(s)*
  11. [ |-A|\ *params* ]
  12. [ |-C|\ *gs_option* ]
  13. [ |-D|\ *outdir* ]
  14. [ |-E|\ *resolution* ]
  15. [ |-F|\ *out_name* ]
  16. [ |-G|\ *ghost_path* ]
  17. [ |-H|\ *factor* ]
  18. [ |-I| ]
  19. [ |-L|\ *listfile* ]
  20. [ **-Mb**\|\ **f**\ *pslayer* ]
  21. [ |-Q|\ [**g**\|\ **p**\|\ **t**][1\|2\|4] ]
  22. [ |-S| ]
  23. [ |-T|\ **b**\|\ **e**\|\ **E**\|\ **f**\|\ **F**\|\ **j**\|\ **g**\|\ **G**\|\ **m**\|\ **s**\|\ **t**\ [**+m**] ]
  24. [ |SYN_OPT-V| ]
  25. [ |-W|\ *params* ]
  26. [ |-Z| ]
  27. [ |SYN_OPT--| ]
  28. |No-spaces|
  29. Description
  30. -----------
  31. **psconvert** converts one or more PostScript files to other formats
  32. (BMP, EPS, JPEG, PDF, PNG, PPM, SVG, TIFF) using Ghostscript. Input file
  33. names are read from the command line or from a file that lists them. The
  34. size of the resulting images is determined by the BoundingBox (or
  35. HiResBoundingBox, if present). As an option, a tight (HiRes)BoundingBox
  36. may be computed first. As another option, it can compute ESRI type world
  37. files used to reference, for instance, tif files and make them be
  38. recognized as geotiff. **Note**: If the PostScript file calls on any of
  39. the Adobe PDF transparency extensions *and* PDF is not the selected output
  40. format, then the file will first be converted to a temporary PDF file
  41. (for the transparency to take effect) before converting the PDF to the
  42. desired output format.
  43. Required Arguments
  44. ------------------
  45. *psfiles*
  46. Names of PostScript files to be converted. The output files will
  47. have the same name (unless **-F** is used) but with the conventional
  48. extension name associated to the raster format (e.g., .jpg for the
  49. jpeg format). Use **-D** to redirect the output to a different
  50. directory.
  51. Optional Arguments
  52. ------------------
  53. .. _-A:
  54. **-A**\ [**+f**\ *fade*][**+g**\ *paint*][**+m**\ *margins*][**+n**][**+p**\ [*pen*]][**+r**][**+s**\ [**m**]\|\ **S**\ *width*/\ *height*][**+u**]
  55. Adjust the BoundingBox and HiResBoundingBox to the minimum required
  56. by the image content. Append **+n** to leave the BoundingBoxes as they are
  57. (e.g., to override any automatic setting of **-A** by **-W**).
  58. Append **+u** to first remove any GMT-produced time-stamps.
  59. Optionally, append **+m** to specify extra margins to extend the bounding box.
  60. Give either one (uniform), two (x and y) or four (individual sides)
  61. margins; append unit [Default is set by :term:`PROJ_LENGTH_UNIT`].
  62. Use the **-A+s**\ *new_width* to resize the output image to exactly *new_width* units.
  63. The default is to use what is set by :term:`PROJ_LENGTH_UNIT`
  64. but you can append a new unit and/or impose different width and height. What happens
  65. here is that Ghostscript will do the re-interpolation work and the final image will
  66. retain the DPI resolution set by **-E**. Use **-A+sm** to set a maximum size and
  67. the new width are only imposed if the original figure width exceeds it. Append
  68. /\ *new_height* to also impose a maximum height in addition to the width.
  69. Alternatively use **-A+S**\ *scale* to scale the image by a constant factor.
  70. Use the **-A+r** to round the HighRes BoundingBox instead of using the ``ceil`` function.
  71. This is going against Adobe Law but can be useful when creating very small images
  72. where the difference of one pixel might matter.
  73. If **-V** is used we also report the dimensions of the illustration.
  74. Use **-A+f**\ *fade* to fade the entire plot towards black (100%) [no fading, 0].
  75. Use **-A+g**\ *paint* to paint the BoundingBox behind the illustration and
  76. use **-A+p**\ [*pen*] to draw the BoundingBox outline (append a pen or accept
  77. the default pen of 0.25p,black). **Note**: If both **+g** and **+f** are used
  78. then we use *paint* as the fade color instead of black.
  79. .. _-C:
  80. **-C**\ *gs_option*
  81. Specify a single, custom option that will be passed on to
  82. Ghostscript as is. Repeat to add several options [none].
  83. .. _-D:
  84. **-D**\ *outdir*
  85. Sets an alternative output directory (which must exist) [Default is
  86. the same directory as the PS files]. Use **-D.** to place the output
  87. in the current directory instead.
  88. .. _-E:
  89. **-E**\ *resolution*
  90. Set raster resolution in dpi [default = 720 for PDF, 300 for others].
  91. **Note**: Ghostscript limits the final width and height pixel dimensions
  92. of a raster to be less than or equal to 65536.
  93. .. _-F:
  94. **-F**\ *out_name*
  95. Force the output file name. By default output names are constructed
  96. using the input names as base, which are appended with an
  97. appropriate extension. Use this option to provide a different name,
  98. but without extension. Extension is still determined automatically.
  99. .. _-G:
  100. **-G**\ *ghost_path*
  101. Full path to your Ghostscript executable. NOTE: For Unix systems
  102. this is generally not necessary. Under Windows, the Ghostscript path
  103. is now fetched from the registry. If this fails you can still add
  104. the GS path to system's path or give the full path here. (e.g.,
  105. **-G**\ c:\\programs\\gs\\gs9.02\\bin\\gswin64c). WARNING: because
  106. of the poor decision of embedding the bits on the gs exe name we
  107. cannot satisfy both the 32 and 64 bits Ghostscript executable names.
  108. So in case of 'get from registry' failure the default name (when no
  109. **-G** is used) is the one of the 64 bits version, or gswin64c
  110. .. _-H:
  111. **-H**\ *factor*
  112. Given the finite dots-per-unit used to rasterize PostScript frames to rasters, the quantizing of features
  113. to discrete pixel will lead to rounding. Some of this is mitigated by the anti-aliasing settings (**-Q**)
  114. which affect lines and text only. The scale *factor* temporarily increases the effective dots-per-unit
  115. by *factor*, rasterizes the plot, then downsamples the image by the same factor at the end. The larger
  116. the *factor*, the smoother the raster. Because processing time increases with *factor* we suggest you
  117. try values in the 2-5 range. Note that raster images can also suffer from quantizing when the original data
  118. have much higher resolution than your raster pixel dimensions. The **-H** option may then be used to smooth
  119. the result to avoid aliasing [no downsampling].
  120. .. _-I:
  121. **-I**
  122. Enforce gray-shades by using ICC profiles. Ghostscript versions
  123. >= 9.00 change gray-shades by using ICC profiles. Ghostscript 9.05
  124. and above provide the '-dUseFastColor=true' option to prevent that
  125. and that is what **psconvert** does by default, unless option **-I** is
  126. set. Note that for Ghostscript >= 9.00 and < 9.05 the gray-shade
  127. shifting is applied to all but PDF format. We have no solution to
  128. offer other than upgrade Ghostscript.
  129. .. _-L:
  130. **-L**\ *listfile*
  131. The *listfile* is an ASCII file with the names of the PostScript
  132. files to be converted.
  133. .. _-M:
  134. **-Mb**\|\ **f**\ *pslayer*
  135. Sandwich the current *psfile* between an optional background (**-Mb**) and
  136. optional foreground (**-Mf**) Postscript plots. These files are expected
  137. to be stand-alone plots that will align when stacked.
  138. .. _-Q:
  139. **-Q**\ [**g**\|\ **p**\|\ **t**][1\|2\|4]
  140. Set the anti-aliasing options for **g**\ raphics or **t**\ ext.
  141. Append the size of the subsample box (1, 2, or 4) [4]. For vector
  142. formats the default is no anti-aliasing (same as *bits* = 1).
  143. For any raster format the default setting is **-Qt4**, while transparent
  144. PNG also adds **-Qg2**. These defaults may be overruled manually.
  145. Optionally, select **-Qp** to turn on generation of Geo PDFs (requires **-Tf** as well).
  146. .. _-S:
  147. **-S**
  148. Print to standard error the Ghostscript command after it has been executed.
  149. This option also prevent all intermediate files from being removed.
  150. .. _-T:
  151. **-Tb**\|\ **e**\|\ **E**\|\ **f**\|\ **F**\|\ **j**\|\ **g**\|\ **G**\|\ **m**\|\ **s**\|\ **t**\ [**+m**]
  152. Sets the output format, where **b** means BMP, **e** means EPS,
  153. **E** means EPS with PageSize command, **f** means PDF, **F** means
  154. multi-page PDF, **j** means JPEG, **g** means PNG, **G** means
  155. transparent PNG (untouched regions are transparent), **m** means
  156. PPM, **s** means SVG, and **t** means TIFF [default is JPEG]. To **bjgt** you can
  157. append **+m** in order to get a monochrome (grayscale) image. The EPS format can be
  158. combined with any of the other formats. For example, **-Tef**
  159. creates both an EPS and a PDF file. The **-TF** creates a multi-page
  160. PDF file from the list of input PS or PDF files. It requires the **-F** option.
  161. See also **NOTES** below.
  162. .. _-V:
  163. .. |Add_-V| unicode:: 0x20 .. just an invisible code
  164. .. include:: explain_-V.rst_
  165. .. _-W:
  166. **-W**\ [**+g**][**+k**][**+t**\ *docname*][**+n**\ *layername*][**+o**\ *foldername*][**+a**\ *altmode*\ [*alt*]][**+l**\ *minLOD/maxLOD*][**+f**\ *minfade/maxfade*][**+u**\ *URL*]
  167. Write a ESRI type world file suitable to make (e.g) .tif files be
  168. recognized as geotiff by software that know how to do it. Be aware,
  169. however, that different results are obtained depending on the image
  170. contents and if the **-B** option has been used or not. The trouble
  171. with the **-B** option is that it creates a frame and very likely
  172. its annotations. That introduces pixels outside the map data extent,
  173. and therefore the map extents estimation will be wrong. To avoid
  174. this problem use **--MAP_FRAME_TYPE**\ =inside option which plots all
  175. annotations and ticks inside the image and therefore does not
  176. compromise the coordinate computations. Pay attention also to the
  177. cases when the plot has any of the sides with whites only because
  178. than the algorithm will fail miserably as those whites will be eaten
  179. by the Ghostscript. In that case you really must use **-B** or use a
  180. slightly off-white color.
  181. Together with **-V** it prints on screen the gdal_translate
  182. (gdal_translate is a command line tool from the GDAL package)
  183. command that reads the raster + world file and creates a true
  184. geotiff file. Use **-W+g** to do a system call to gdal_translate
  185. and create a geoTIFF image right away. The output file will have a
  186. .tiff extension.
  187. The world file naming follows the convention of jamming a 'w' in the
  188. file extension. So, if output is tif **-Tt** the world file is a
  189. .tfw, for jpeg we have a .jgw and so on. This option automatically
  190. sets **-A** **-P**.
  191. Use **-W+k** to create a minimalist KML file that allows loading the
  192. image in GoogleEarth. Note that for this option to work it is necessary that the postscript
  193. image must have been created with **-JX** or **-Jx** cartesian projection of
  194. geographical coordinates. If not, a warning is issued but the KML
  195. file is created anyway. Several modifier options are available to
  196. customize the KML file in the form of **+**\ *opt* strings. Append
  197. **+t**\ *title* to set the document title [GMT KML Document],
  198. **+n**\ *layername* to set the layer name, and
  199. **+a**\ */altmode*\ [*altitude*] to select one of 5 altitude modes
  200. recognized by Google Earth that determines the altitude (in m) of
  201. the image: **G** clamped to the ground, **g** append altitude
  202. relative to ground, **a** append absolute altitude, **s** append
  203. altitude relative to seafloor, and **S** clamp it to the seafloor.
  204. Control visibility of the layer with the **+l**\ *minLOD/maxLOD* and
  205. **+f**\ *minfade/maxfade* options. Finally, if you plan to leave the
  206. image itself on a server and only distribute the KML, use
  207. **+u**\ *URL* to prepend the URL to the image reference. If you are
  208. building a multi-component KML file then you can issue a KML snipped
  209. without the KML header and trailer by using the **+o**\ *foldername*
  210. modification; it will enclose the image and associated KML code
  211. within a KML folder of the specified name. See the
  212. `KML documentation <https://code.google.com/apis/kml/documentation/>`_
  213. for further explanation.
  214. **Note**: If any of your titles or names contain a plus symbol next to
  215. a letter it can be confused with an option modifier. Escape such
  216. plus signs by placing a backslash in front of it. Alternatively,
  217. enclose the string in double quotes and then the entire **-W**
  218. argument in single-quotes (or vice versa).
  219. Further notes on the creation of georeferenced rasters.
  220. **psconvert** can create a georeferenced raster image with a world
  221. file OR uses GDAL to convert the GMT PostScript file to geotiff.
  222. GDAL uses `PROJ <https://proj.org/>`_ for its projection library. To provide with the
  223. information it needs to do the georeferencing, GMT 4.5 embeds a
  224. comment near the start of the PostScript file defining the
  225. projection using **PROJ** syntax. Users with pre-GMT v4.5 PostScript
  226. files, or even non-GMT ps files, can provide the information
  227. **psconvert** requires by manually editing a line into the
  228. PostScript file, prefixed with %%PROJ.
  229. For example the command::
  230. gmt coast -JM0/12c -R-10/-4/37/43 -W1 -Di -Bg30m --MAP_FRAME_TYPE=inside -ps cara
  231. adds this comment line::
  232. %%PROJ: merc -10.0 -4.0 37.0 43.0 -1113194.908 -445277.963
  233. 4413389.889 5282821.824 +proj=merc +lon_0=0 +k=-1 +x_0=0 +y_0=0
  234. +a=6378137.0 +b=6356752.314245 +ellps=WGS84 +datum=WGS84 +units=m +no_defs
  235. where 'merc' is the keyword for the coordinate conversion; the 2 to
  236. 5th elements contain the map limits, 6 to 9th the map limits in
  237. projected coordinates and the rest of the line has the regular **PROJ**
  238. string for this projection.
  239. **-Z**
  240. Remove the input PostScript file(s) after the conversion.
  241. The input file(s) will **not** be removed in case of failures.
  242. .. include:: explain_help.rst_
  243. Notes
  244. -----
  245. The conversion to raster images (BMP, JPEG, PNG, PPM or TIFF) inherently
  246. results in loss of details that are available in the original
  247. PostScript file. Choose a resolution that is large enough for the
  248. application that the image will be used for. For web pages, smaller dpi
  249. values suffice, for Word documents and PowerPoint presentations a higher
  250. dpi value is recommended. **psconvert** uses the loss-less DEFLATE
  251. compression technique when creating PDF and PNG files and LZW compression
  252. for TIFF images. For smaller dpi images, such as required for building
  253. animations, the use of **-Qt**\ 4 and **-Qg**\ 4 may help sharpen text and lines,
  254. as will the **-H** option.
  255. EPS is a vector (not a raster) format. Therefore, the **-E** option has
  256. no effect on the creation of EPS files. Using the option **-Te** will
  257. remove setpagedevice commands from the PostScript file and will adjust the
  258. BoundingBox when the **-A** option is used. Note the original and
  259. required BoundingBox is limited to integer points, hence Adobe added the
  260. optional HiResBoundingBox to add more precision in sizing. The **-A**
  261. option calculates both and writes both to the EPS file and is subsequently
  262. used in any rasterization, if requested. When the **-TE** option is used, a
  263. new setpagedevice command is added that will indicate the actual pagesize for
  264. the plot, similar to the BoundingBox. Note that when the command setpagedevice
  265. exists in a PostScript file that is included in another document, this can wreak
  266. havoc on the printing or viewing of the overall document. Hence, **-TE** should only
  267. be used for "standalone" PostScript files.
  268. Although PDF and SVG are also vector formats, the **-E** option has an effect on
  269. the resolution of pattern fills and fonts that are stored as bitmaps in
  270. the document. **psconvert** therefore uses a larger default resolution
  271. when creating PDF and SVG files. **-E** also determines the resolution of the
  272. boundingbox values used to indicate the size of the output PDF.
  273. In order to obtain high-quality PDF or SVG files, the
  274. */prepress* options are in effect, allowing only loss-less DEFLATE
  275. compression of raster images embedded in the PostScript file.
  276. Although **psconvert** was developed as part of the GMT, it can be
  277. used to convert PostScript files created by nearly any graphics
  278. program. However, **-A+u** is GMT-specific.
  279. The **ghostscript** program continues to be developed and occasionally its
  280. developers make decisions that affect **psconvert**. As of version 9.16 the
  281. SVG device has been removed. Fortunately, quality SVG graphics can be obtained
  282. by first converting to PDF and then install and use the package **pdf2svg**.
  283. See :ref:`include-gmt-graphics` of the **GMT Technical Reference and Cookbook** for more
  284. information on how **psconvert** is used to produce graphics that can be
  285. inserted into other documents (articles, presentations, posters, etc.).
  286. The conversion to Geo PDFs have proven unstable and could create PDF files that could
  287. not be opened. We have therefore made this an optional setting that now requires
  288. the **-Qp** option to activate, since most users are unaware of GeoPDFs anyway.
  289. Examples
  290. --------
  291. .. include:: explain_example.rst_
  292. To convert the file psfile.ps to PNG using a tight BoundingBox::
  293. gmt psconvert psfile.ps -A -Tg
  294. To convert the file map.ps to PDF, extend the BoundingBox by 0.2 cm,
  295. fill it with lightblue paint and draw outline with a thick pen::
  296. gmt psconvert map.ps -A+m0.2c+glightblue+pthick -Tf
  297. To create a 5 cm PNG version at 300 dpi of our example_01.ps file::
  298. gmt psconvert example_01.ps -A+s5c -Tg
  299. To create a 3 pages PDF file from 3 individual PS files::
  300. gmt psconvert -TF -Fabc a.ps b.ps c.ps
  301. To create a simple linear map with :doc:`coast` and convert it to tif with a
  302. .tfw the tight BoundingBox computation::
  303. gmt coast -JX12cd -R-10/-4/37/43 -W1 -Di -Bg30m -G200 --MAP_FRAME_TYPE=inside -ps cara
  304. gmt psconvert cara.ps -Tt -W
  305. To create a Mercator version of the above example and use GDAL to
  306. produce a true geotiff file::
  307. gmt coast -JM0/12c -R-10/-4/37/43 -W1 -Di -Bg30m -G200 --MAP_FRAME_TYPE=inside -ps cara
  308. gdalwarp -s_srs +proj=merc cara.tif carageo.tiff
  309. To create a Polar Stereographic geotiff file of Patagonia::
  310. gmt coast -JS-55/-60/15c -R-77/-55/-57.5/-48r -Di -Gred -Bg2 --MAP_FRAME_TYPE=inside -ps patagonia
  311. gmt psconvert patagonia.ps -Tt -W+g -V
  312. To create a simple KML file for use in Google Earth, try::
  313. gmt grdimage lonlatgrid.nc -Jx1 -Ccolors.cpt -B0g2 --MAP_FRAME_TYPE=inside -ps tile
  314. gmt psconvert tile.ps -Tg -W+k+t"my title"+l256/-1 -V
  315. (These commands assume that Ghostscript can be found in your system's path.)
  316. Ghostscript Options
  317. -------------------
  318. Most of the conversions done in **psconvert** are handled by
  319. Ghostscript. On most Unixes this program is available as **gs**; for
  320. Windows there is a version called **gswin32c**. Ghostscript accepts a
  321. rich selection of command-line options that modify its behavior. Many of
  322. these are set indirectly by the options available above. However,
  323. hard-core usage may require some users to add additional options to
  324. fine-tune the result. Use **-S** to examine the actual command used, and
  325. add custom options via one or more instances of the **-C** option. For
  326. instance, to turn on image interpolation for all images, improving image
  327. quality for scaled images at the expense of speed, use
  328. **-C**-dDOINTERPOLATE. See www.ghostscript.com for complete
  329. documentation.
  330. Making KMZ files
  331. ----------------
  332. If you have made a series of KML files (which may depend on other items
  333. like local PNG images), you can consolidate these into a single KMZ file
  334. for saving space and for grouping related files together. The bash function
  335. **gmt_build_kmz** in the :doc:`gmt_shell_functions.sh` can be used to
  336. do this. You need to source gmt_shell_functions.sh first before you can
  337. use it.
  338. See Also
  339. --------
  340. :doc:`gmt`,
  341. :doc:`coast`
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...