damon

ヾ(・ω・*)

  • they/them

┐(︶▽︶)┌

 

Better things are possible

 

thank you for everything, cohost!

 


ffxiv



Cro
@Cro
bash scripting
stitching ACNL QR codes

made a little tool that checks through a folder of animal crossing: new leaf patterns, finds the ones that are meant to be in a set of 4, then stitches them together

before the nintendo servers went down i went hard on archiving a bunch of pretty dream towns, since then i've been slowly going through them, exploring them and saving out any custom QR codes for patterns

a bunch of problems cropped up when trying to manually organise the QR codes tho :
  • some QR code images are standalone single ones, and some are in sets of 4, but they are all named in sequence on when they were added to the sd card
  • the sets of 4 wouldn't be too hard to lose, i want to stitch each group together into a single image
  • even worse, each folder on the SD card holds a max of 999? files, then creates a new folder, so sometimes sets are broken up by this and named PIC98, PIC99, PIC00, PIC01
  • and i don't want to have to sort them into sets vs single QR codes manually
so first, how to detect if they're in a set of 4 or not? the only consistent difference between them is the tiny #/4 on a blue bubble in a corner

1/4 in a set
solo qr code

was wondering if i could get it to detect if that corner of an image is blue, and it took a while trying different things, but eventually worked out a bunch of steps that worked

cropping images

first thing was to clip off the bottom left corner of each image, as it's the only bit that's relevant and we need to check for what colours are in it

good ole imagemagick to the rescue

the first is using -chop, which outputs the remainder of the image after cropping a designated amount off.

this will remove 50 pixels from the top of an image :
convert image_in.png -gravity North -chop 0x50 image_out.png
the "0x50" is how many pixels to chop off from the width x the height of the image. -gravity is used to pick which side of the image to chop off.

so for our case, setting -gravity NorthEast -chop 335x205 is what we want, as we want to keep the bottom left 65x35 pixels (of a 400x240 image).
convert image_in.png -gravity NorthEast -chop 333x204 image_out.png
the problem i have with this is how annoying it is to work out the number of pixels to chop off. and what if I want to trim down to the same number of pixels from a bunch of differently sized images?

luckily we can check what the size of an image is, using identify (also part of imagemagick)
identify -format '%wx%h' image_in.png
so i extended the script to check each image for what it's dimensions are, and then subtract the amount of pixels we want to keep

bash people are probs going to really hate how long this is and ask why i didn't just pipe it all together, come at me programmers

trim_W=65
trim_H=35

whichside=NorthEast

# choosing $whichside : remember this needs to be the OPPOSITE side of the edge/corner you want to keep ( example: NorthEast if wanting to keep the bottom left corner, West if wanting to keep the center right side, etc. )
# - - - - - - - - - - - - - - - - - - - - -
full_W=$(identify -format '%w' "$filename")
full_H=$(identify -format '%h' "$filename")
crop_W=$(( $full_W - $trim_W ))
crop_H=$(( $full_H - $trim_H ))

convert "$filename" -gravity $whichside -chop ${crop_W}x${crop_H} "$fileout"


and here's the resulting crop

gonna have to split this into a second post whoops, it's getting stupid long. next part i'll go into the detecting colours in an image so we can find out whether each image is part of a set
credits:

◆ axe pixel sprite by ReHoeass

◆ gulliver render from Nintendo's New Leaf

◆ other icons by foollovers


You must log in to comment.