diff --git a/ansible/roles/common/templates/noaa-v2.conf.j2 b/ansible/roles/common/templates/noaa-v2.conf.j2 index 4beb7b10..3cb06372 100644 --- a/ansible/roles/common/templates/noaa-v2.conf.j2 +++ b/ansible/roles/common/templates/noaa-v2.conf.j2 @@ -62,6 +62,7 @@ PRUNE_OLDEST={{ delete_oldest_n }} METEOR_RECEIVER={{ meteor_receiver }} NOAA_CROP_TELEMETRY={{ noaa_crop_telemetry|lower }} IMAGE_ANNOTATION_LOCATION={{ image_annotation_location }} +EXTEND_FOR_ANNOTATION={{ extend_for_annotation|lower }} GROUND_STATION_LOCATION='{{ ground_station_location }}' NOAA_DAY_ENHANCEMENTS='{{ noaa_daytime_enhancements }}' NOAA_NIGHT_ENHANCEMENTS='{{ noaa_nighttime_enhancements }}' diff --git a/config/settings.yml.sample b/config/settings.yml.sample index 40c0ec6a..76282071 100644 --- a/config/settings.yml.sample +++ b/config/settings.yml.sample @@ -78,6 +78,9 @@ delete_audio: false # noaa_crop_telemetry - whether to crop the left/right telemetry in image captures # image_annotation_location - where to place the annotation in images - valid options are: # NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast +# extend_for_annotation - whether to create a black extension on the north/south location of +# the image to place the annotation into (vs. overlaying on the captured data) +# (note: this will ONLY work if the image_annotation_location is NOT one of [West|Center|East]) # produce_noaa_pristine_image - whether to produce a pristine image (unmodified) for larger # composite-based use cases # produce_noaa_pristine_histogram - whether to produce a histogram of the NOAA pristine image @@ -98,6 +101,7 @@ flip_meteor_image: true produce_spectrogram: true noaa_crop_telemetry: false image_annotation_location: 'NorthWest' +extend_for_annotation: false produce_noaa_pristine_image: false produce_noaa_pristine_histogram: false produce_polar_az_el_graph: false diff --git a/config/settings_schema.json b/config/settings_schema.json index d85ec247..ab6f67c4 100644 --- a/config/settings_schema.json +++ b/config/settings_schema.json @@ -79,6 +79,7 @@ "image_annotation_location": { "type": "string" }, + "extend_for_annotation": { "type": "boolean" }, "produce_noaa_pristine_image": { "type": "boolean" }, "produce_noaa_pristine_histogram": { "type": "boolean" }, "produce_polar_az_el_graph": { "type": "boolean" }, @@ -180,6 +181,7 @@ "produce_spectrogram", "noaa_crop_telemetry", "image_annotation_location", + "extend_for_annotation", "produce_noaa_pristine_image", "produce_noaa_pristine_histogram", "produce_polar_az_el_graph", diff --git a/scripts/common.sh b/scripts/common.sh index 58788399..b9e5914a 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -32,6 +32,7 @@ fi # binary helpers CONVERT="/usr/bin/convert" GMIC="/usr/bin/gmic" +IDENTIFY="/usr/bin/identify" MEDET_ARM="/usr/bin/medet_arm" METEOR_DEMOD="/usr/bin/meteor_demod" PREDICT="/usr/bin/predict" diff --git a/scripts/image_processors/meteor_normalize_annotate.sh b/scripts/image_processors/meteor_normalize_annotate.sh index b96faab2..241eba68 100755 --- a/scripts/image_processors/meteor_normalize_annotate.sh +++ b/scripts/image_processors/meteor_normalize_annotate.sh @@ -49,24 +49,70 @@ yml_config=$(echo "${yml_config}" | sed -e "s/\.\.\.$/gain: $gain\n.../") # vars for image manipulation tmp_dir="${NOAA_HOME}/tmp/annotation" rendered_file="${tmp_dir}/index.html" +annotation="${tmp_dir}/annotation.png" # generate annotation html and copy any assets $SCRIPTS_DIR/tools/jinja2_to_file.py "${NOAA_HOME}/config/annotation/annotation.html.j2" "${yml_config}" "${rendered_file}" find $NOAA_HOME/config/annotation/* -type f -not -name "*.j2" -exec cp {} "${tmp_dir}/" \; # generate annotation png and crop to content -$WKHTMLTOIMG --enable-local-file-access --format png --quality 100 --transparent "file://${rendered_file}" "${tmp_dir}/annotation.png" -$CONVERT -format png "${tmp_dir}/annotation.png" -background none -flatten -trim +repage "${tmp_dir}/annotation.png" +$WKHTMLTOIMG --enable-local-file-access --format png --quality 100 --transparent "file://${rendered_file}" "${annotation}" +$CONVERT -format png "${annotation}" -background none -flatten -trim +repage "${annotation}" -# generate final image with annotation, doubling the annotation for account -# for the LRPT image sizes, keeping aspect ratio for original image -img_w=$($CONVERT "${tmp_dir}/annotation.png" -format "%w" info:) -img_h=$($CONVERT "${tmp_dir}/annotation.png" -format "%h" info:) +# resize the annotation appropriately, keeping aspect ratio +img_w=$($CONVERT "${annotation}" -format "%w" info:) +img_h=$($CONVERT "${annotation}" -format "%h" info:) new_img_w=$((img_w * 2)) new_img_h=$((img_h * 2)) -echo $new_img_w -echo $new_img_h -$CONVERT -format jpg "${INPUT_JPG}" \( "${tmp_dir}/annotation.png" -resize "${new_img_w}x${new_img_h}^" \) \ - -gravity $IMAGE_ANNOTATION_LOCATION \ - -geometry +10+10 \ - -composite "${OUTPUT_JPG}" +$CONVERT "${annotation}" -resize "${new_img_w}x${new_img_h}^" "${annotation}" + +# extend the image if the user specified and didn't use +# one of [West|Center|East] for the annotation location +# TODO: DRY this up - this is the same code as in the NOAA script +annotation_location=$(echo $IMAGE_ANNOTATION_LOCATION | tr '[:upper:]' '[:lower:]') +extend_annotation=0 +if [ "${EXTEND_FOR_ANNOTATION}" == "true" ]; then + if [[ "${annotation_location}" =~ ^(west|center|east)$ ]]; then + log "You specified extending the annotation, but your annotation location $annotation_location does not support it" "WARN" + else + extend_annotation=1 + fi +fi + +# generate the final image with annotation +if [ $extend_annotation -eq 1 ]; then + # calculate expansion height needed to fit annotation + annotation_h=$($IDENTIFY -format "%h" "${annotation}") + img_expand_px=$(($annotation_h + 20)) + out_file=$(basename $OUTPUT_JPG) + tmp_out="${NOAA_HOME}/tmp/${out_file%%.*}-tmp.jpg" + + # create pixels north or south depending on annotation location + gravity_var="South" + if [[ "${annotation_location}" =~ ^(northwest|north|northeast)$ ]]; then + gravity_var="North" + fi + + $CONVERT -quality 100 \ + -format jpg "${INPUT_JPG}" \ + -gravity "${gravity_var}" \ + -background black \ + -splice "0x${img_expand_px}" "${tmp_out}" + + # generate final image with annotation + $CONVERT -format jpg "${tmp_out}" "${annotation}" \ + -gravity $IMAGE_ANNOTATION_LOCATION \ + -geometry +0+10 \ + -composite "${OUTPUT_JPG}" + + # clean up + rm "${tmp_out}" +else + $CONVERT -format jpg "${INPUT_JPG}" "${annotation}" \ + -gravity $IMAGE_ANNOTATION_LOCATION \ + -geometry +10+10 \ + -composite "${OUTPUT_JPG}" +fi + +# clean up the annotation +rm "${annotation}" diff --git a/scripts/image_processors/noaa_normalize_annotate.sh b/scripts/image_processors/noaa_normalize_annotate.sh index 883f984a..cbc99ef4 100755 --- a/scripts/image_processors/noaa_normalize_annotate.sh +++ b/scripts/image_processors/noaa_normalize_annotate.sh @@ -58,9 +58,52 @@ find $NOAA_HOME/config/annotation/* -type f -not -name "*.j2" -exec cp {} "${tmp $WKHTMLTOIMG --enable-local-file-access --format png --quality 100 --transparent "file://${rendered_file}" "${tmp_dir}/annotation.png" $CONVERT -format png "${tmp_dir}/annotation.png" -background none -flatten -trim +repage "${tmp_dir}/annotation.png" -# generate final image with annotation -$CONVERT -quality $QUALITY \ - -format jpg "${INPUT_JPG}" "${tmp_dir}/annotation.png" \ - -gravity $IMAGE_ANNOTATION_LOCATION \ - -geometry +10+10 \ - -composite "${OUTPUT_JPG}" +# extend the image if the user specified and didn't use +# one of [West|Center|East] for the annotation location +annotation_location=$(echo $IMAGE_ANNOTATION_LOCATION | tr '[:upper:]' '[:lower:]') +extend_annotation=0 +if [ "${EXTEND_FOR_ANNOTATION}" == "true" ]; then + if [[ "${annotation_location}" =~ ^(west|center|east)$ ]]; then + log "You specified extending the annotation, but your annotation location $annotation_location does not support it" "WARN" + else + extend_annotation=1 + fi +fi + +# generate the final image with annotation +if [ $extend_annotation -eq 1 ]; then + # calculate expansion height needed to fit annotation + annotation_h=$($IDENTIFY -format "%h" "${tmp_dir}/annotation.png") + img_expand_px=$(($annotation_h + 20)) + out_file=$(basename $OUTPUT_JPG) + tmp_out="${NOAA_HOME}/tmp/${out_file%%.*}-tmp.jpg" + + # create pixels north or south depending on annotation location + gravity_var="South" + if [[ "${annotation_location}" =~ ^(northwest|north|northeast)$ ]]; then + gravity_var="North" + fi + + $CONVERT -quality 100 \ + -format jpg "${INPUT_JPG}" \ + -gravity "${gravity_var}" \ + -background black \ + -splice "0x${img_expand_px}" "${tmp_out}" + + # generate final image with annotation + $CONVERT -quality $QUALITY \ + -format jpg "${tmp_out}" "${tmp_dir}/annotation.png" \ + -gravity $IMAGE_ANNOTATION_LOCATION \ + -geometry +0+10 \ + -composite "${OUTPUT_JPG}" + + # clean up + rm "${tmp_out}" +else + # generate final image with annotation + $CONVERT -quality $QUALITY \ + -format jpg "${INPUT_JPG}" "${tmp_dir}/annotation.png" \ + -gravity $IMAGE_ANNOTATION_LOCATION \ + -geometry +10+10 \ + -composite "${OUTPUT_JPG}" +fi