I am cropping a tif image file using gdal_translate but the resulting file is of bigger size compared to the original file.
Here is the sample command that I am using to crop the image
gdal_translate -srcwin 4000 4500 2000 3000 Ortho.tif Ortho_cropped.tif
You can compress the output too with the following
gdal_translate -srcwin 4000 4500 2000 3000 -co COMPRESS=DEFLATE -co PREDICTOR=2 Ortho.tif Ortho_cropped.tif
This uses deflate compression which is often quite effective. A predictor of 2 is often nice for integer values, while you can change the predictor to 3 if your values are floats.
You can use other compressions too like ZSTD if you are using gdal >= 2.3 which should be faster and archive similar compression rates. If you do not care about lossy compression, you can even use JPEG.
If you do not know the compression of your original image you can see what it is using the command gdalinfo Ortho.tif where the compression is described under Image Structure Metadata
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
I have a big GeoTIFF that I want to stream through a WMS within GeoServer (v.2.11). The size of the image is about 7GB, consisting on a very large high resolution RGB image. I have allowed enough heap space within JVM in order to display the imagery. However, I would like to compress the image so it can be more responsive when exploring through and so it will allocate less memory. I have followed some of the recommendations here.
My strategy was to compress the GeoTIFF with JPEG compression and use that as a data store in GeoServer. However, this seems not to work. This is the gdal command I have used to translate the image:
gdal_translate -of GTiff -co "BIGTIFF=YES" -co "COMPRESS=JPEG" -co "TILED=YES" -co "BLOCKXSIZE=512" -co "BLOCKYSIZE=512" -a_srs "EPSG:3057" D:\raster\image.tif
D:\raster\image_translate.tif
When previewing the image with openlayers, I got nothing, just a blank basemap. The log from GeoServer told me that something in the projection went bad:
2017-06-09 13:16:47,551 INFO [geoserver.wms] -
Request: getServiceInfo
2017-06-09 13:16:47,561 WARN [lite.gridcoverage2d] - Could not reduce the grid geometry inside the valid area bounds: ReferencedEnvelope[-1.7976931348623157E308 : 1.7976931348623157E308, -85.0 : 85.0]
Grid geometry isGridGeometry2D[GeneralGridEnvelope[0..357, 0..357], PARAM_MT["Affine",
PARAMETER["num_row", 3],
PARAMETER["num_col", 3],
PARAMETER["elt_0_0", 0.7353351955307262],
PARAMETER["elt_0_2", 584219.1848475977],
PARAMETER["elt_1_1", -0.7353351955307262],
PARAMETER["elt_1_2", 383937.61122240225]]]
2017-06-09 13:16:47,566 ERROR [geoserver.ows] -
org.geoserver.platform.ServiceException: Error rendering coverage on the fast path
I then tried to use another compression strategy with GDAL, i.e. "DEFLATE":
gdal_translate -of GTiff -co COMPRESS=DEFLATE -co PREDICTOR=2 -co ZLEVEL=9 -co "BIGTIFF=YES" -a_srs "EPSG:3057" D:\raster\image.tif D:\raster\image_translate2.tif
And that worked when previewing in openlayers. Here is the GeoServer log:
2017-06-09 13:28:27,137 INFO [geoserver.wms] -
Request: getServiceInfo
2017-06-09 13:28:27,146 WARN [lite.gridcoverage2d] - Could not reduce the grid geometry inside the valid area bounds: ReferencedEnvelope[-1.7976931348623157E308 : 1.7976931348623157E308, -85.0 : 85.0]
Grid geometry isGridGeometry2D[GeneralGridEnvelope[0..357, 0..357], PARAM_MT["Affine",
PARAMETER["num_row", 3],
PARAMETER["num_col", 3],
PARAMETER["elt_0_0", 0.7353351955307262],
PARAMETER["elt_0_2", 584219.1848475977],
PARAMETER["elt_1_1", -0.7353351955307262],
PARAMETER["elt_1_2", 383937.61122240225]]]
2017-06-09 13:28:27,231 INFO [geoserver.wms] -
Request: getMap
I have also tried to perform gdal_translate using JPEG compression and no tiling, and I got also errors with the GeoServer log and the openlayers preview displayed nothing.
So my question is, what is the best strategy to compress GeoTIFF files to be used in a WMS? At the moment, seems that DEFLATE is the only one working, but the compression is not the best. Has anyone been able to successfully upload a JPEG compressed GeoTIFF to Geoserver?
If it's any help the way I do it is as follows.
First I chop the raster up into smaller tiles, size is not important, for me it's generally either 256x256, 512x512 or 1024x124.
I use a number of different programs from gdal2tiles.py to my own homegrown c# apps.
What's important is that the tiles are square.
Once I have the tiles in a folder, I then use gdaltindex
This creates a shapefile with one square for each tile, correctly georeferenced (assuming your raster was) along with the name of each tile, I usually tell gdaltindex to write absolute paths to the shapefile.
I then reference the shape as a tile layer in mapserver, I can't say if geoserver will accept a shape based tile index, but since gdal can make them and the other WMS based server available open source (mapserver) can use them, then I would be very suprised if geoserver was not able to use them.
This would work in the case of tiff greater than 2GB. GeoServer can efficiently deal with large TIFF with overviews, as long as the TIFF is below the 2GB size limit.
Using image pyramid makes the tiff load faster as it makes multiple mosaic of images at different zoom levels.
Use the following command:-
mkdir bmpyramid
gdal_retile.py -v -r bilinear -levels 4 -ps 2048 2048 -co "TILED=YES" -co "COMPRESS=JPEG" -targetDir bmpyramid bmreduced.tiff
You can check here
https://docs.geoserver.org/stable/en/user/tutorials/imagepyramid/imagepyramid.html
I would like to convert a .png into a .pdf (I guess it's actually being embedded) whilst reducing the filesize. So I thought, jpeg-compression might be a good choice. So far it works well with ImageMagick using 2 commands: Converting it into a .jpg first and then converting it into a .pdf.
convert image.png -quality 92 image.jpg
convert image.jpg image.pdf
Now, is there a way to do that in only one command?
In ImageMagick, try
convert image.png -compress JPEG -quality 92 image.pdf
I want to rotate a 351K PDF named 08-file.pdf using CLI tools. I've tried imagemagick:
convert 08-file.pdf -rotate 90 08-file-rotated.pdf
But the original quality:
Suffered serious degradation:
I've tried adding the -density 300x300 argument, but the outcome was a 2.5M file, nearly one order of magnitude larger than the original, which is a huge waste.
Any idea how to losslessly rotate a PDF file using imagemagick?
I always had bad results in converting/altering pdf file with imagemagik/convert (bad resolution, or huge file). Playing with options -compress -density -quality was always frustrating and a waste of time (but i am no expert).
Proposal 1: pdftk
So I would recommend pdftk (you may need to install it via apt-get install)
Try :
pdftk 08-file.pdf cat 1-endright output 08-file-rotated.pdf
For old version of pdftk (v<3) rotation was indicated only by one letter:
N: 0, E: 90, S: 180, W: 270, L: -90, R: +90, D: +180. The same command was:
pdftk 08-file.pdf cat 1-endR output 08-file-rotated.pdf
From another post on this site, I have a brief an explanation of the syntax
pdftk input.pdf cat 1-endsouth output output.pdf
# \_______/ \___/\___/ \________/
# input file range | output file
# direction
You can see also https://linux.die.net/man/1/pdftk
Edit 2020:
Proposal 2: qpdf
I have found another alternative which is equivalent: qpdf, easier to remember and more powerful
see QPDF manual
#Syntax (you can rotate only some pages of the document -- see the manual --
qpdf --rotate=[+|-]angle[:page-range]
# Example
qpdf in.pdf out.pdf --rotate=+180
Other options worth to consider
pdfjam
PDF manipulation tools (CLI)
To be considered if pdftk is not available on your system.
pdfjam looks quite similar to pdftk
pdfsam
This is a toolbox to modify pdf files with a GUI (graphical user interface).
Code is open source and multiplateform.
Please use -compress lossless option:
convert -rotate 90 -compress lossless 08-file.pdf 08-file-rotated.pdf
From the documentation:
https://www.imagemagick.org/script/command-line-options.php#compress
Lossless refers to lossless JPEG, which is only available if the JPEG
library has been patched to support it.
Another option is to use the following command:
jhead -cmd "jpegtran -progressive -perfect -rotate 270 &i > &o"
Image-0001.jpeg
It will write output to a temporary file and when it succeeds it will overwrite the original file:
Cmd:jpegtran -progressive -perfect -rotate 270 "Image-0001.jpeg" >
"h1xQ6q"
Modified: Image-0001.jpeg