Following is the code I'm using to compress set of .tif images to .jpg. My objective is to iterate through each .tif image and create a new set of compressed jpg images.
from osgeo import gdal
import os
for filename in os.listdir(os.getcwd()):
#print(filename.split("."))
if(filename.split(".")[1] == "tif"):
print(filename.split(".")[0])
gdal_translate \
-co COMPRESS=JPEG \
-co TILED=YES \
filename.split(".")[0].tif filename.split(".")[0].jpg
Though I don't see an error in this code. I followed the technique mentioned in this blog post., I'm getting the following error when I try to execute the above code. The error message is:
File "test.py", line 8
-co COMPRESS=JPEG \
^
SyntaxError: invalid syntax
What seems to be the issue here?
gdal_translate
is a commandline executable, not a python module. Either run it from a command prompt/shell terminal or use thegdal.VectorTranslate
python method.