User:Escallic

From OpenStreetMap Wiki
Jump to navigation Jump to search
Userboxes
OSM Logo This user submits data to OpenStreetMap under the name
escallic.
Babel user information
en-N This user has a native understanding of English.
de-2 Dieser Benutzer beherrscht Deutsch auf fortgeschrittenem Niveau.
Users by language

Here lies a draft for a Wiki page for OSHW (Open Source Hardware) as it pertains to OSM. This is distinct from the current Hardware guide as it was never intended to be open source hardware but rather a recycling of post-market devices. It includes projects whose design files and source code are mostly readily available for everyone to get started. It will hopefully serve as a template for future projects.

Recommended Software

  • exiftool
  • FreeCAD
  • KiCAD

Example

C'est un clamp.

In the image of a bicycle clamp (see on the right), the CAD sourcefile is attached in the metadata of the JPEG. It is not only the image. Rather, it is also the customizable and FreeCAD-editable parametric model. Below is a process that describes how one may share or overwrite source files here to this Wiki using a script, provided that the screenshot image of their design is a JPEG format.

  1. Usage Examples:
  2. Eg.1: ./jpeg-attach pic.jpg src.zip unzip
  3. Eg.2: ./jpeg-attach img.jpg model.FCStd freecad
  4. Eg.3: ./jpeg-attach 000.jpg mesh.stl fstl

We save the below script in a file called jpeg-attach, make executable with chmod a+x jpeg-attach:

#!/bin/bash
# Attach a Source File to a JPEG Image.

F_JPG=$1            # Input File (argument 1)
F_SRC=$2            # Source File (argument 2)
APP=$3              # Application (argument 3)
D_TMP=/tmp          # Temp Folder
SOI="ffd8"          # Start of Image
NUL="00"            # NUL Byte Char

COM="The original $F_JPG file hosts its own source. Extract with: "
COM+="exiftool -b -ThumbnailImage $F_JPG >> .$F_JPG && dd if=.$F_JPG bs=1 "
COM+="skip=\$(exiftool -ThumbnailOffset .$F_JPG | sed \"s/.*\: //g\") "
COM+="count=\$(exiftool -ThumbnailLength .$F_JPG | sed \"s/.*\: //g\") "
COM+="| xxd -c 1 -p | tr -d \"\n\" | sed \"s/ff00/ff/g\" | xxd -r -p > $F_SRC "
COM+="&& $APP $F_SRC"

# Make temp folder.
2>/dev/null mkdir /tmp

# Make temp copy.
cp $F_JPG $F_JPG.jpg

# Escape 0xFF source bytes to distinguish them from EXIF markers.
xxd -c 1 -p $F_SRC | tr -d "\n" | sed "s/ff/ff00/g" | xxd -r -p > $D_TMP/$F_SRC

# Make a thumbnail with the same size as the Source file.
let i=${#SOI}/2
let I=$(stat -c %s $D_TMP/$F_SRC)
echo $SOI | xxd -r -p > $D_TMP/$F_JPG
echo "for (i=$i; i<$I; i++) \"00\"" | bc | xxd -r -p >> $D_TMP/$F_JPG

# Insert the thumbnail into the Input file.
exiftool "-ThumbnailImage<=$D_TMP/$F_JPG" $F_JPG

# Get the new offset and length of the Input file.
let off=$(exiftool -ThumbnailOffset $F_JPG | sed "s/.*\: //g")
let len=$(exiftool -ThumbnailLength $F_JPG | sed "s/.*\: //g")

# Copy Input file bytes that precede the Source.
dd if=$F_JPG of=$D_TMP/$F_JPG bs=$off count=1

# Insert Source file bytes to this new file.
dd if=$D_TMP/$F_SRC >> $D_TMP/$F_JPG

# Copy Input file bytes that succeed the Source.
dd if=$F_JPG bs=$((off+len)) skip=1 >> $D_TMP/$F_JPG

# Move this file to the original file.
mv $D_TMP/$F_JPG $F_JPG

# Remove Temporary file.
rm $D_TMP/$F_SRC

# Use temp copy as thumbnail
exiftool "-ThumbnailImage<=$F_JPG" $F_JPG.jpg

# Move special file to original file.
mv $F_JPG.jpg $F_JPG

# Add a comment.
exiftool -comment="$COM" $F_JPG