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.
This commit is contained in:
Ben Harris
2022-12-31 15:20:17 +00:00
parent f63810fbc8
commit b403f8f97a

View File

@ -42,13 +42,13 @@ $back = $plist[0];
# Crop rows and columns off the image to find the central rectangle # Crop rows and columns off the image to find the central rectangle
# of non-background stuff. # of non-background stuff.
$ystart = 0; $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 = $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 = 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 = $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 # Decide how much border we're going to put back on to make the
# image perfectly square. # image perfectly square.