Skip to content

Commit

Permalink
Merge pull request #1 from verachell/dev
Browse files Browse the repository at this point in the history
fix:several fixes for better UX
  • Loading branch information
verachell authored Nov 21, 2022
2 parents 4aa58ae + 6aad151 commit 6a258ee
Showing 122 changed files with 47 additions and 27 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ From one or more of your local photos, obtains subsections from each photo givin

This is a shell script specific to bash.

This creates a series of non-overlapping horizontal rectangular subsections from local JPG images in the working directory. In addition it creates a series of circular png images suitable for profile image placeholders. The resultant 2 new sets of images are placed into new directories. This script uses imagemagick, which is bundled by default into most linux installations.
This creates a series of non-overlapping horizontal rectangular subsections from local JPG images in the working directory. In addition it creates a series of circular png images suitable for profile image placeholders. The resultant 2 new sets of images are placed into new directories. This script uses imagemagick.

To check if you have imagemagick, type ```man convert``` and the manual will come up if you have it. If it doesn't come up, you can install imagemagick using your Linux package manager.

@@ -19,22 +19,14 @@ The remainder of the files in this repository are example input and output image

To use, place this script in the same Linux working directory as your source image files. Ensure the script has executable permissions. At the command line, type './photosubsec.sh' (without the quotes). No arguments are needed; the script will act on all images in the working directory which start with IMG and end with .jpg or .JPG

This creates directories 'SUBSEC_horizontal' and 'SUBSEC_profile'; be aware that if these already exist inside your working directory they may be overwritten. Your horizontal jpgs will be placed in SUBSEC_horizontal and the circular pngs suitable for profile images will be in SUBSEC_profile.
This creates directories 'SUBSEC-horizontal' and 'SUBSEC-profile'; be aware that if these already exist inside your working directory they may be overwritten. Your horizontal jpgs will be placed in SUBSEC-horizontal and the circular pngs suitable for profile images will be in SUBSEC-profile.

### Ability to use your own photos as input
This script uses whatever images you have in the working directory where you're running this script. (Note: it actually uses images that start with IMG and end with .jpg or .JPG since that's how most camera images are formatted - of course, you can adjust the script to your own needs). The advantage of using your own images is that you then don't need to worry about spending time to find public domain images, etc.

## Example input and output
This repository shows example input and output. The 3 JPG files in the main directory are the input photos (taken by me). The 2 SUBSEC directories contain the output images. This allows you to get a feel for how it works before trying it with your own photos.

Here are a few of the profile photos:

- https://github.com/verachell/Image-Generator-from-Photo-Subsections/blob/main/SUBSEC_profile/prof_tempIMG_1472-6.png
- https://github.com/verachell/Image-Generator-from-Photo-Subsections/blob/main/SUBSEC_profile/prof_tempIMG_1472-21.png
- https://github.com/verachell/Image-Generator-from-Photo-Subsections/blob/main/SUBSEC_profile/prof_tempIMG_1472-23.png

These were generated from this input photo https://github.com/verachell/Image-Generator-from-Photo-Subsections/blob/main/IMG_1472.JPG . There are more examples you can browse in this repository.

## Limitations and caveats
Source images are best suited when they are in landscape format and approximately 2400x1600 but the script works well on other sizes and aspect ratios. Do not worry about not having the exact size or the aspect ratio; this is all taken care of by the script. It will still work with images other than the recommended size or different aspect ratios, but in those situations be aware some parts of your source photo will never get used (small-ish bits on the right and on the bottom) and/or there will be some lossiness in the resultant new images (originals remain unmodified). The degree of lossiness you experience is proportional to how far away your dimensions and aspect ratios are from 2400x1600. Your aspect ratio is always maintained, it's just that scaling of your photo as a whole might be applied during the process (again, without modifying the original).

File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added SUBSEC-horizontal/IMG-1467-4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SUBSEC-horizontal/IMG-1467-5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SUBSEC-horizontal/IMG-1467-6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added SUBSEC-horizontal/IMG-1470-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SUBSEC-horizontal/IMG-1470-10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added SUBSEC-horizontal/IMG-1470-12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added SUBSEC-horizontal/IMG-1470-7.jpg
Binary file added SUBSEC-horizontal/IMG-1470-8.jpg
File renamed without changes
Binary file added SUBSEC-horizontal/IMG-1472-0.jpg
File renamed without changes
Binary file added SUBSEC-horizontal/IMG-1472-10.jpg
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added SUBSEC-horizontal/IMG-1472-3.jpg
Binary file added SUBSEC-horizontal/IMG-1472-4.jpg
Binary file added SUBSEC-horizontal/IMG-1472-5.jpg
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added SUBSEC-profile/prof-sqsubsecIMG-1467-1.png
Binary file added SUBSEC-profile/prof-sqsubsecIMG-1467-14.png
Binary file added SUBSEC-profile/prof-sqsubsecIMG-1467-15.png
Binary file added SUBSEC-profile/prof-sqsubsecIMG-1467-4.png
Binary file added SUBSEC-profile/prof-sqsubsecIMG-1470-10.png
Binary file added SUBSEC-profile/prof-sqsubsecIMG-1470-18.png
Binary file added SUBSEC-profile/prof-sqsubsecIMG-1470-2.png
Binary file added SUBSEC-profile/prof-sqsubsecIMG-1470-20.png
Binary file added SUBSEC-profile/prof-sqsubsecIMG-1470-21.png
Binary file added SUBSEC-profile/prof-sqsubsecIMG-1472-18.png
Binary file added SUBSEC-profile/prof-sqsubsecIMG-1472-20.png
62 changes: 45 additions & 17 deletions photosubsec.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
#!/bin/bash
# Creates a series of non-overlapping horizontal rectangular subsections from local JPG images in
# the working directory. Also creates a series of circular png images suitable for profile image
# placeholders. The resultant 2 new sets of images are placed into new directories.
# This script uses imagemagick, which is bundled by default into most linux installations.
# Creates a series of non-overlapping horizontal rectangular subsections from local JPG images
# beginning with IMG in the working directory. Also creates a series of circular png images suitable
# for profile image placeholders. The resultant 2 new sets of images are placed into new directories.
# This script uses imagemagick. If you do not have imagemagick (check via 'man convert') then install
# it via your linux package manager.
#
# USAGE: place this script in the same Linux working directory as your source image files. Ensure it
# has executable permissions. At the command line, type './photosubsec.sh' (without the quotes).
# No arguments are needed; the script will act on all images in the working directory which start
# with IMG and end with .jpg or .JPG.
#
# first create square and rectangular pics as needed
# This creates directories 'SUBSEC_horizontal' and 'SUBSEC_profile'; be aware that if these
# This creates directories 'SUBSEC-horizontal' and 'SUBSEC-profile'; be aware that if these
# already exist they may be overwritten

# start with horizontal rectangular images
mkdir -p SUBSEC_horizontal
somefiles=false
echo -n "Creating horizontal images from each pic"
mkdir -p SUBSEC-horizontal

# test if glob exists first
if compgen -G "IMG*.JPG" > /dev/null; then
somefiles=true
for f in $(ls IMG*.JPG)
do
convert $f -strip -resize 2400x1600 -resize 2400x1600^ -crop 2400x1600+0+0 +repage -crop 600x400 +repage +adjoin SUBSEC_horizontal/$(basename -s .JPG $f).jpg
echo -n "."
convert $f -strip -resize 2400x1600 -resize 2400x1600^ -crop 2400x1600+0+0 +repage -crop 600x400 +repage +adjoin SUBSEC-horizontal/$(basename -s .JPG $f).jpg
done
fi

# repeat for lowercase jpg extensions
if compgen -G "IMG*.jpg" > /dev/null; then
somefiles=true
for f in $(ls IMG*.jpg)
do
convert $f -strip -resize 2400x1600 -resize 2400x1600^ -crop 2400x1600+0+0 +repage -crop 600x400 +repage +adjoin SUBSEC_horizontal/$(basename -s .jpg $f).jpg
echo -n "."
convert $f -strip -resize 2400x1600 -resize 2400x1600^ -crop 2400x1600+0+0 +repage -crop 600x400 +repage +adjoin SUBSEC-horizontal/$(basename -s .jpg $f).jpg
done
fi


if $somefiles; then
# next do circular pngs
mkdir -p SUBSEC_profile
mkdir -p SUBSEC-profile

# First make a circular mask, then crop to circle, as described in
# https://stackoverflow.com/questions/41959355/how-can-i-combine-these-commands-to-achieve-circular-crop-in-imagemagick
@@ -43,29 +50,50 @@ mkdir -p SUBSEC_profile
convert -size 100x100 xc:Black -fill White -draw 'circle 50 50 50 1' -alpha Copy SUBSECprof_mask.png

# next generate square tiles in png format without the mask
echo " "
echo -n "Getting images ready for profile sections - this takes longer"

if compgen -G "IMG*.JPG" > /dev/null; then
for f in $(ls IMG*.JPG)
do
convert $f -strip -resize 2400x1600 -resize 2400x1600^ -crop 2400x1600+0+0 +repage -crop 400x400 +repage +adjoin SUBSEC_profile/temp$(basename -s .JPG $f).png
echo -n "."
convert $f -strip -resize 2400x1600 -resize 2400x1600^ -crop 2400x1600+0+0 +repage -crop 400x400 +repage +adjoin SUBSEC-profile/sqsubsec$(basename -s .JPG $f).png
done
fi

# repeat for lowercaes jpg extensions
# repeat for lowercase jpg extensions
if compgen -G "IMG*.jpg" > /dev/null; then
for f in $(ls IMG*.jpg)
do
convert $f -strip -resize 2400x1600 -resize 2400x1600^ -crop 2400x1600+0+0 +repage -crop 400x400 +repage +adjoin SUBSEC_profile/temp$(basename -s .jpg $f).png
echo -n "."
convert $f -strip -resize 2400x1600 -resize 2400x1600^ -crop 2400x1600+0+0 +repage -crop 400x400 +repage +adjoin SUBSEC-profile/sqsubsec$(basename -s .jpg $f).png
done
fi

# apply mask to square tiles
for f in $(ls SUBSEC_profile/temp*.png)
echo ""
echo -n "Making circular profile images"
# apply circular mask to square tiles
for f in $(ls SUBSEC-profile/sqsubsec*.png)
do
convert $f -resize 100x100 SUBSECprof_mask.png -compose CopyOpacity -composite SUBSEC_profile/prof_$(basename -s .png $f).png
echo -n "."
convert $f -resize 100x100 SUBSECprof_mask.png -compose CopyOpacity -composite SUBSEC-profile/prof-$(basename -s .png $f).png
done

rm SUBSEC_profile/temp*
echo ""
echo "Cleaning up"
rm SUBSEC-profile/sqsubsec*
rm SUBSECprof_mask.png

# this next bit is not essential - it simply replaces the underscore character '_' with the minus sign
# character '-' in the generated photo filenames. This feature is provided to ensure the resultant
# photo filenames are compatible for use in YeetWords. If you are not subsequently using these files in
# YeetWords, it won't matter whether or not you execute the final statements.
rename 'y/_/-/' SUBSEC-horizontal/*.jpg
rename 'y/_/-/' SUBSEC-profile/*.png
echo "Done"
else
echo ""
echo "Unable to proceed. Did not find any jpg files starting with IMG"
fi


0 comments on commit 6a258ee

Please sign in to comment.