Skip to content

Commit

Permalink
Facsimile conversion: Don't re-generate existing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
thvitt committed Oct 14, 2016
1 parent 9de2e75 commit ad2e1a8
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions convert.sh
Expand Up @@ -37,6 +37,15 @@ rm "$current_dir/temp_input_folders.txt"
cd "$input_dir"
find . -type f -name "*.tif" -print0 | while IFS= read -r -d '' file
do
# Generating the JSON file is the last step, so we can use that as an
# indicator on whether we need to do something for this input file at all
json_file=$(echo "$file" | sed "s#^\.#"$output_metadata"#;s/\.tif$/\.json/" )
if [ -s "$json_file" ]
then
continue
fi


#convert tga->jpg and create preview images with max size 240x360 (widthXheight)
out_file1=$(echo "$file" | sed "s#^\.#"$input_dir"#" )
out_file2=$(echo "$file" | sed "s#^\.#"$output_jpg"#;s/\.tif$/_0\.jpg/" )
Expand All @@ -47,13 +56,6 @@ do
convert "${out_file1}"[0] -strip -resize 240x360 "${out_file3}"


#create json metadata
echo " creating json metadata"
json_file=$(echo "$file" | sed "s#^\.#"$output_metadata"#;s/\.tif$/\.json/" )
image_width=$(identify $file 2>/dev/null | sed -n '1 p' | cut -d\ -f3 | cut -dx -f1)
image_height=$(identify $file 2>/dev/null | sed -n '1 p' | cut -d\ -f3 | cut -dx -f2)
printf "{\n \"imageWidth\": %s,\n \"imageHeight\": %s,\n \"tileWidth\": %s,\n \"tileHeight\": %s,\n \"zoomLevels\": %s\n}" ${image_width} ${image_height} ${tile_width} ${tile_height} ${zoom_levels} > "${json_file}"

#scale images
echo " creating scaled images"
for i in `seq 0 $((zoom_levels-1))`
Expand All @@ -75,6 +77,15 @@ do
# echo " $cmd"
convert "${scaled_file}" -strip -crop ${tile_width}x${tile_height} -set filename:tile %[fx:page.x/${tile_width}]_%[fx:page.y/${tile_height}] +repage +adjoin "${tiled_file}"
done

#create json metadata
echo " creating json metadata"
#json_file=$(echo "$file" | sed "s#^\.#"$output_metadata"#;s/\.tif$/\.json/" )
image_width=$(identify $file 2>/dev/null | sed -n '1 p' | cut -d\ -f3 | cut -dx -f1)
image_height=$(identify $file 2>/dev/null | sed -n '1 p' | cut -d\ -f3 | cut -dx -f2)
printf "{\n \"imageWidth\": %s,\n \"imageHeight\": %s,\n \"tileWidth\": %s,\n \"tileHeight\": %s,\n \"zoomLevels\": %s\n}" ${image_width} ${image_height} ${tile_width} ${tile_height} ${zoom_levels} > "${json_file}"


done

# return to the folder that we started in
Expand Down

0 comments on commit ad2e1a8

Please sign in to comment.