Skip to content

Instantly share code, notes, and snippets.

@comstock
comstock / lossy_jp2_psnr_43
Last active November 1, 2018 19:10
OpenJPEG, JPEG200 lossy compression encoding example with quality set to 42 decibels
opj_compress -i <input.tif> -o <output.jp2> -p RLCP -t 1024,1024 -EPH -SOP -OutFor jp2 -I -q 42
@comstock
comstock / md5_of_text_sting_commandline.md
Last active May 10, 2018 17:29
pushing a text string through a pipe to md5sum requires echo's -n switch which prevents echo from outputting a trailing newline

echo -n | md5sum

@comstock
comstock / file_type_inventory.R
Last active September 6, 2019 20:24
Generate an inventory of file types found in a filesystem
pacman::p_load(
readr,
httr,
jsonlite,
curl,
stringr,
dplyr,
xtable,
formattable,
htmlTable,
@comstock
comstock / transferImageTechnicalMetadata
Last active October 2, 2018 14:04
Transfer image technical metadata from source file to JP2 derivative #exiftool
exiftool -ext tif -tagsfromfile @ -srcfile %f.jp2 [directory name] -XMP:format= -ImageHistory='Image technical metadata values were copied (via exiftool) from a source image to this derivative JP2 copy.' -overwrite_original
@comstock
comstock / mogrify_convert.md
Last active November 29, 2023 11:28
Convert all the JP2 images in a directory to JPEGs using GraphicsMagick's Mogrify; crop image edges with Imagemagick's Convert

Format change & resize

  • mogrify -format jpg -quality 85 *.jp2
  • mogrify -format jpg -quality 85 -resize 2048x *.jp2 # specifying pixel-width limit.

Rotate

  • mogrify rotateMe.jpg -rotate 90
  • convert input.jpg -rotate 90 output.jpg
@comstock
comstock / countValidJP2
Last active July 29, 2020 20:15
How to count the number of JPEG2000 files found to be valid using jpylyzer
jpylyzer *jp2 | grep --extended-regexp "<isValid format=\"jp2\">True</isValid>" | wc --lines
@comstock
comstock / exiftool_csv.md
Last active November 26, 2025 14:35
Use exiftool to generate table of image data in CSV format

Gather image metadata using Exiftool from a directory of images

Metadata is captured as a CSV file facilitating analysis of image-groupings.

Command line elements:

exiftool -recurse [image dir name] -csv -@ [file listing of sought metadata fields] [filename pattern] > [output filename]

Example:

@comstock
comstock / base ubuntu install
Last active June 9, 2023 18:47
Installing Ubuntu linux packages
sudo apt-get update; sudo apt-get upgrade -y ;sudo apt-get install -y curl zstd webp glabels lynx cifs-utils gpa gnupg2 libpam-google-authenticator network-manager-openconnect-gnome build-essential libjpeg-dev default-jre network-manager-vpnc network-manager-vpnc-gnome tree liblcms2-dev libtiff-dev libpng-dev libopenjp2-tools enscript libtiff-tools imagemagick jasper httpie cups cmake imagemagick leptonica-progs autoconf-archive libpng-dev libleptonica-dev tesseract-ocr golang-go hugo pandoc shotwell tesseract-ocr-all graphicsmagick feh autokey-gtk gimp liblcms2-dev libtiff-dev libpng-dev libz-dev git maven file default-jdk openssh-server python3-jpylyzer pqiv p7zip-full net-tools xterm git-lfs tasksel slim lightdm ; sudo tasksel install lubuntu-core libheif1 libheif-dev
# Installing X11 on Linux, see: https://phoenixnap.com/kb/how-to-install-a-gui-on-ubuntu
sudo apt-get install curl -y ; export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"; echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_R
@comstock
comstock / convert tiff to 8 bits per channel
Last active April 28, 2023 19:27
Using graphicsmagick, convert a directory of TIFF files into uncompressed 8 bit per channel TIFF files
gm mogrify -format tif -compress none -define tiff:bits-per-sample=8 *.tif
mogrify -format tif -depth 8 *.tif
@comstock
comstock / siegfried_PRONOM.txt
Last active September 30, 2018 11:03
Siegfried PRONOM file identification commandline tool #DROID
# Identify all files and subdirectories within ~/images dir, generate md5 checksums for each file and save output as CSV
sf -hash md5 -csv ~/images > ~/images/sf.csv