Utilities for React Pig
Using this file assumes you are using Cloudinary as your image hosting provider. You could take the concepts within it and write it for your own image hosting provider of choice.
Running the file will loop through a local folder (and its subfolders) of images & videos, it will generate metadata on each item, and will upload them to Cloudinary.
To use upload.js
- Create a Cloudinary account.
- Create a file named
.env
and save it in the same folder asupload.js
. Paste in the following with your Cloudinary credentials filled out;
cloud_name="abc123"
api_key="1234567890"
api_secret="yourapisecret"
- Run the file thusly
node upload --in=./yourLocalImgPath/ --cloudinaryFolder=yourCloudinaryFolderName
--in
- your local folder where your images are at (it will also recursively use files found in subfolders too)--cloudinaryFolder
- the folder in Cloudinary (optional, if omitted will use the Cloudinary root folder)
The Apple Photos app conveniently has a feature where it can export your photos into folders named with location and date. If this folder structure is present in your --in
folder, upload.js
will automatically use the folder names to add location
and date
metadata to the images. This is handy for grouping images later.
To export your images from Apple Photos;
- Select all images to export
- File -> Export -> Export Photos -> Filename: Use Title & Subfolder Format: Moment Name
- When running upload.js just point
--in
at the generated folder
upload.js
will automatically add metadata to the images uploaded to Cloudinary. This includes;
location
- the location detected from the Apple Photos folder, as mentioned abovedate
- the date detected from the Apple Photos folder, as mentioned abovecreated
- the file created date from the original file. Often it's the same asdate
lat
- latitude as extracted from the original files EXIF datalng
- longitude as extracted from the original files EXIF datadominantColor
- the dominant colour of the image, for videos this is always#fff
- neighbourhood, city, country, streetName, - generating these requires a reverse geocode lookup based on the
lat
lng
, so if you require these you'll need to add a Google API key into the.env
file, example below, simply adding the key will enable the feature;
google_api="123"
Once you've uploaded your images, you'll need to generate the JSON file to provide to React Pig.
Assuming you have a Cloudinary account and have followed the upload.js
process;
node generateJSON --cloudinaryFolder=whateverFolderYouWantJsonFrom --out=./outputFilename.json
Pig React can display images in groups. Most common would be to group by date. groupify.js
will take the JSON file created by generateJSON.js
, sort it by date (newest first), group each image by date, and convert it to a format which tells Pig React to render groups.
Example usage;
node groupify --in=./input.json --out=./output.json
MIT © nickmcmillan