20

I want to develop a web portal that will show the images dynamically produced by QGIS, but QGIS provided tiff images are too big in size and it is not possible to show it on website using image viewers. That's why I have decided to convert those tiff images into jpg/jpeg to reduce in size as well as browser friendly so that I can show those images on my website easily. But I don't know how to convert tiff images into jpg/jpeg using gdal commands.

Please help me in this regard.

3
  • two questions: 1) do you want only to change(convert) the image type from tiff to jpg or do you also want to resize? 2)which operating system do you use?
    – Kurt
    May 26, 2012 at 15:22
  • I also want to resize and I'm using ubuntu May 26, 2012 at 17:13
  • If you have a WMS then the choice of format is determined by the the client, so a web client can request jpeg or png and a desktop GIS can select TIFF, and no need to convert yourself
    – nmtoken
    Dec 10, 2017 at 18:42

2 Answers 2

36

try this with gdal:

gdal_translate -of JPEG -scale -co worldfile=yes input.tiff output.jpg

it also create worldfile too...

i hope it helps you...

6
  • thanks to those who commented on my post. Aragon your solution worked for me May 26, 2012 at 17:22
  • one more thing how can I do it dynamically so that I can show the image on the website May 26, 2012 at 17:42
  • If you keep getting solid black output, you might need to specify the min and max values for scale. I used gdalinfo to get the min and max, then provide them like ... -scale 0 0.158 ... Jan 31, 2018 at 3:03
  • Good, but it discards any color information from the band rendering. Do you know how to keep it?
    – Rodrigo
    Nov 7, 2019 at 13:41
  • Legend @aragon! Thank you for this solution. Was using imagemagic's convert, but it's not lossless, so the resulting jpg was losing some detail. But this seems only get the jpg data out of the tiff file, no recompression going on as far as I can see.
    – Mint
    Sep 7, 2021 at 5:49
14

Hei!

Choose Raster menu - Conversion - Translate (Convert format). Then choose *Input file* for the image You want to convert. Under the *Output file* You can choose the format You need. There is .jpg too (with some 20+ file types).

I got 40MB large .tiff file, after conversion its only 1,6 MB as .jpg.

2
  • 3
    Good, but it discards any color information from the band rendering. Do you know how to keep it?
    – Rodrigo
    Nov 7, 2019 at 13:41
  • I use as input float32 RGB image .tif file and when I store it as .jpeg is totally black.... Why I get that result? Jul 25, 2022 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.