diff --git a/pocs/utils/images/__init__.py b/pocs/utils/images/__init__.py index 1f2dc81ce..6ac60308e 100644 --- a/pocs/utils/images/__init__.py +++ b/pocs/utils/images/__init__.py @@ -88,9 +88,28 @@ def make_pretty_image(fname, timeout=15, **kwargs): # pragma: no cover warn("File doesn't exist, can't make pretty: {}".format(fname)) if fname.endswith('.cr2'): - return _make_pretty_from_cr2(fname, timeout=timeout, **kwargs) + pretty_path = _make_pretty_from_cr2(fname, timeout=timeout, **kwargs) elif fname.endswith('.fits'): - return _make_pretty_from_fits(fname, **kwargs) + pretty_path = _make_pretty_from_fits(fname, **kwargs) + else: + warn("File must be a Canon CR2 or FITS file.") + return None + + # Symlink latest.jpg to the image; first remove the symlink if it already exists. + if os.path.exists(pretty_path) and pretty_path.endswith('.jpg'): + latest_path = '{}/images/latest.jpg'.format(os.getenv('PANDIR')) + try: + os.remove(latest_path) + except FileNotFoundError: + pass + try: + os.symlink(pretty_path, latest_path) + except Exception as e: + warn("Can't link latest image: {}".format(e)) + + return pretty_path + else: + return None def _make_pretty_from_fits( diff --git a/scripts/cr2_to_jpg.sh b/scripts/cr2_to_jpg.sh index 02bcfc25c..586c6c1e9 100755 --- a/scripts/cr2_to_jpg.sh +++ b/scripts/cr2_to_jpg.sh @@ -4,7 +4,6 @@ FNAME=$1 NAME=$2 JPG=${FNAME/cr2/jpg} -LATEST=${PANDIR}/images/latest.jpg # Use exiftool to extract preview if it exists if hash exiftool 2>/dev/null; then @@ -21,4 +20,4 @@ fi # Make thumbnail from jpg. convert ${JPG} -thumbnail 1280x1024 -background black -fill red \ - -font ubuntu -pointsize 24 label:"${NAME}" -gravity South -append ${LATEST} + -font ubuntu -pointsize 24 label:"${NAME}" -gravity South -append ${JPG}