ref: b403f8f97a97f9f55205d57149fd355a09727bd4
parent: f63810fbc89158d5637e4f554436c80140569024
author: Ben Harris <bjh21@bjh21.me.uk>
date: Sat Dec 31 10:20:17 EST 2022
Support the generation of icons from uniformly-coloured screenshots The square.pl script removed all pixels that were the same colour as the edge ones, even if that meant removing all of the pixels. Now it stops removing pixels at 1x1 so that there will be something left for ImageMagick to work on.
--- a/icons/square.pl
+++ b/icons/square.pl
@@ -42,13 +42,13 @@
# Crop rows and columns off the image to find the central rectangle
# of non-background stuff.
$ystart = 0;
-$ystart++ while $ystart < $h and scalar(grep { $_ ne $back } map { $data->[$ystart*$w+$_] } 0 .. ($w-1)) == 0;
+$ystart++ while $ystart < $h - 1 and scalar(grep { $_ ne $back } map { $data->[$ystart*$w+$_] } 0 .. ($w-1)) == 0;
$yend = $h-1;
-$yend-- while $yend >= $ystart and scalar(grep { $_ ne $back } map { $data->[$yend*$w+$_] } 0 .. ($w-1)) == 0;
+$yend-- while $yend > $ystart and scalar(grep { $_ ne $back } map { $data->[$yend*$w+$_] } 0 .. ($w-1)) == 0;
$xstart = 0;
-$xstart++ while $xstart < $w and scalar(grep { $_ ne $back } map { $data->[$_*$w+$xstart] } 0 .. ($h-1)) == 0;
+$xstart++ while $xstart < $w - 1 and scalar(grep { $_ ne $back } map { $data->[$_*$w+$xstart] } 0 .. ($h-1)) == 0;
$xend = $w-1;
-$xend-- while $xend >= $xstart and scalar(grep { $_ ne $back } map { $data->[$_*$w+$xend] } 0 .. ($h-1)) == 0;
+$xend-- while $xend > $xstart and scalar(grep { $_ ne $back } map { $data->[$_*$w+$xend] } 0 .. ($h-1)) == 0;
# Decide how much border we're going to put back on to make the
# image perfectly square.