Alphabet Pattern Matching We've had a lot of alphabet challenges.  For this challenge, you are passed the output of an alphabet challenge, and you need to output the pattern scaled to size N. 

For example, if N=5 and you were passed the L-phabet:

ABCDEFGHIJKLMNOPQRSTUVWXYZ
BBCDEFGHIJKLMNOPQRSTUVWXYZ
CCCDEFGHIJKLMNOPQRSTUVWXYZ
DDDDEFGHIJKLMNOPQRSTUVWXYZ
EEEEEFGHIJKLMNOPQRSTUVWXYZ
FFFFFFGHIJKLMNOPQRSTUVWXYZ
GGGGGGGHIJKLMNOPQRSTUVWXYZ
HHHHHHHHIJKLMNOPQRSTUVWXYZ
IIIIIIIIIJKLMNOPQRSTUVWXYZ
JJJJJJJJJJKLMNOPQRSTUVWXYZ
KKKKKKKKKKKLMNOPQRSTUVWXYZ
LLLLLLLLLLLLMNOPQRSTUVWXYZ
MMMMMMMMMMMMMNOPQRSTUVWXYZ
NNNNNNNNNNNNNNOPQRSTUVWXYZ
OOOOOOOOOOOOOOOPQRSTUVWXYZ
PPPPPPPPPPPPPPPPQRSTUVWXYZ
QQQQQQQQQQQQQQQQQRSTUVWXYZ
RRRRRRRRRRRRRRRRRRSTUVWXYZ
SSSSSSSSSSSSSSSSSSSTUVWXYZ
TTTTTTTTTTTTTTTTTTTTUVWXYZ
UUUUUUUUUUUUUUUUUUUUUVWXYZ
VVVVVVVVVVVVVVVVVVVVVVWXYZ
WWWWWWWWWWWWWWWWWWWWWWWXYZ
XXXXXXXXXXXXXXXXXXXXXXXXYZ
YYYYYYYYYYYYYYYYYYYYYYYYYZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZ


You would need to output:

ABCDE
BBCDE
CCCDE
DDDDE
EEEEE


For the purposes of explanation, I'll be using only ABCD, instead of the full alphabet.  You need to be able to match the L-phabet (above), as well as the following patterns:

The single line:

ABCD    or     A
               B
               C
               D


The single line repeated N times

ABCD    or    AAAA
ABCD          BBBB
ABCD          CCCC
ABCD          DDDD


The Tabula Recta:

ABCD
BCDA
CDAB
DABC


This alphabet triangle:

A      or   AAAAAAA
AB           BBBBB
ABC           CCC
ABCD           D
ABC
AB
A


We also have half triangles in lots of varieties:

A           AAAA      A        ABCD
BB          BBB       AB       ABC
CCC         CC        ABC      AB
DDDD        D         ABCD     A


Finally, the square:

AAAAAAA
ABBBBBA
ABCCCBA
ABCDCBA
ABCCCBA
ABBBBBA
AAAAAAA


All of the above patterns are of size 4.  However, you will be passed a pattern of size 26, as well as an N between 1 and 26, and you need to scale the pattern.  You do not need to handle any other patterns.


The output for 1 will always be the single character A
The output for 26 will always be the same, full-sized pattern passed in.
Trailing spaces are allowed at the end of each line, as well as a trailing newline at the end
You can find all patterns of size 26 here


This is a code-golf, so do it in as few bytes as possible!
PHP, 502 Bytes

&lt;?$c=count($x=explode("\n",$_GET[p]));for($t=$u=$o="",$f="substr",$n=0;$n&lt;$g=$_GET["n"];$n++){if(2651==$l=strlen($s))$o.=$f($x[$n],0,$g).$f($x[$n],1-$g)."\n";elseif($l==1026)echo($t=$f($x[$n],0,$g)).$f(strrev($t),1)."\n";elseif($f($s,-1)=="Y")echo$f($x[$n],0,$g-$n).$f($x[$n],-$n,$n)."\n";elseif($l==376&amp;&amp;$f($s,-2,1)=="\n")echo$f($x[$n],0,$g-$n)."\n";elseif($l==726){$t.=$x[$n]."\n";$n+1==$g?:$u=$x[$n]."\n".$u;}else echo$f($x[$n]??"",0,$g)."\n";}if($o)echo$o.substr(strrev($o),2*$g+1);if($t)echo$t.$u;


Works with the string length of a pattern. A pattern has these conditions.
Letter at begin an end. CR are removed.

Expanded

foreach($p as$s){ # all patterns in an array
    $c=count($x=explode("\n",$s));
    for($t=$u=$o="",$f="substr",$n=0;$n&lt;$g=$_GET["n"];$n++){
    if(2651==$l=strlen($s))$o.=$f($x[$n],0,$g).$f($x[$n],1-$g)."\n";
# square pattern
    elseif($l==1026)echo($t=$f($x[$n],0,$g)).$f(strrev($t),1)."\n";
#alphabet triangle up down
    elseif($f($s,-1)=="Y")echo$f($x[$n],0,$g-$n).$f($x[$n],-$n,$n)."\n";
# Tabula recta
    elseif($l==376&amp;&amp;$f($s,-2,1)=="\n")echo$f($x[$n],0,$g-$n)."\n";
# two half triangle
    elseif($l==726){$t.=$x[$n]."\n";$n+1==$g?:$u=$x[$n]."\n".$u;}
#alphabet triangle left right
    else echo$f($x[$n]??"",0,$g)."\n";
# all other
    }
    if($o)echo$o.substr(strrev($o),2*$g+1);
    if($t)echo$t.$u;
}