[Question]
  [
# Introduction
I think everyone agrees that nice pictures have to have a nice frame. But most challenges on this site about ASCII-Art just want the raw picture and don't care about it's preservation.  
Wouldn't it be nice if we had a program that takes some ASCII-Art and surrounds it with a nice frame?
# The Challenge
Write a program that takes some ASCII-Art as input and outputs it surrounded by a nice frame.
**Example:**
```
*****
 ***
  *
 ***
*****
```
becomes
```
╔═══════╗
║ ***** ║
║  ***  ║
║   *   ║
║  ***  ║
║ ***** ║
╚═══════╝
```
* You have to use the exact same characters for the frame as in the example: `═ ║ ╔ ╗ ╚ ╝`
* The top and the bottom of the frame get inserted before the first and after the last line of the input.
* The left and rights parts of the frame have to have exact one space padding to the widest line of the input.
* There may be no leading or trailing whitespaces in the output. Only a trailing newline is allowed.
* You may assume that the input has no unnecessary leading whitespaces.
* You may assume that the input has no trailing whitespaces on any line.
* You don't have to handle empty input.
* The input will only contain printable ASCII-characters and newlines.
# Rules
* Function or full program allowed.
* [Default rules](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods) for input/output.
* [Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) apply.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so lowest byte-count wins. Tiebreaker is earlier submission.
**Happy Coding!**
*Using some great ASCII-Art, that was produced in any challenge on this site, as input to your program and showing it with a nice frame is highly encouraged!*
  
[Answer]
## Haskell, 139 bytes
```
q=length
g x|l<-lines x,m<-maximum$q<$>l,s<-[-1..m]>>"═"='╔':s++"╗\n"++(l>>= \z->"║ "++z++([q z..m]>>" ")++"║\n")++'╚':s++"╝"
```
As an example I'm framing [snowman "12333321"](https://codegolf.stackexchange.com/a/49709/34531).
```
*Main> putStrLn $ g " _===_\n (O.O)\n/(] [)\\\n ( : )"
╔═════════╗
║  _===_  ║
║  (O.O)  ║
║ /(] [)\ ║
║  ( : )  ║
╚═════════╝
```
How it works:
```
bind
  l: input split into lines
  m: maximum line length
  s: m+2 times ═
build top line
prepend left frame to each line, pad with spaces, append right frame
build bottom line.
```
[Answer]
## JavaScript (ES6), 138 bytes
This is 138 bytes in the IBM866 encoding, which at time of writing is still supported in Firefox, but 152 in UTF-8.
```
s=>`╔${t='═'.repeat(w=2+Math.max(...(a=s.split`
`).map(s=>s.length)))}╗
${a.map(s=>('║ '+s+' '.repeat(w)).slice(0,w+1)).join`║
`}║
╚${t}╝`
```
[Answer]
## CJam, 45 chars / 52 bytes
```
qN/_z,)[_)'═*N]2*C,3%'╔f+.\4/@@f{Se]'║S@2$N}*
```
Trying to avoid those expensive 3-byte chars was... interesting.
[Try it online](http://cjam.aditsu.net/#code=qN%2F_z%2C%29%5B_%29'%E2%95%90*N%5D2*C%2C3%25'%E2%95%94f%2B.%5C4%2F%40%40f%7BSe%5D'%E2%95%91S%402%24N%7D*&input=%20%20__%0A%20%2F%20%20%5C%0A%20%5C__%2F%0A%7C%20%7C%0A%7C%20%7C_____%20%20%20%20%2F%0A%7C%20%7C%20%20%20%20____%2F%0A%7C%20%7C___%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A-----%7C%20%20%7C%0A%7C%20%20%20%7C%7C%20%20%7C%0A%7C%20%20%20%7C%7C%20%20%7C)
### Explanation
```
qN/                   Split input by newline
_z,                   Zip and get length L, i.e. length of longest line
)                     Increment -> L+1
[_)'═*N]              Make two-element array of "═"*(L+2) and newline
2*                    Double the array, giving ["═"*(L+2) "\n" "═"*(L+2) "\n"]
C,                    range(12), i.e. [0 1 2 ... 11]
3%                    Every third element, i.e. [0 3 6 9]
'╔f+                  Add "╔" to each, giving "╔╗╚╝"
.\                    Vectorised swap with the previous array, giving
                      ["╔" "═"*(L+2) "╗" "\n" "╚" "═"*(L+2) "╝" "\n"]
4/                    Split into chunks of length 4
@@                    Move split input and L+1 to top
f{...}                Map with L+1 as extra parameter...
  Se]                   Pad line to length L+1, with spaces
  '║S                   Put "║" and space before it
  2$N                   Put "║" and newline after it
*                     Join, putting the formatted lines between the top and bottom rows
```
[Answer]
# Bash, 173 171 150 148  147 bytes, 157 136 134 133 characters
```
q(){((n=${#2}>n?${#2}:n));};mapfile -tc1 -C q v;for((p=++n+1;p;--p));do z+=═;done;echo ╔$z╗;printf "║ %-${n}s║\n" "${v[@]}";echo ╚$z╝
```
### *Multiline:*
```
q() {
    (( n = ${#2} > n ? ${#2} : n))
}
mapfile -tc1 -C q v
for((p=++n+1;p;--p))
do 
    z+=═
done
echo ╔$z╗
printf "║ %-${n}s║\n" "${v[@]}"
echo ╚$z╝
```
### Example execution:
```
bash -c 'q(){((n=${#2}>n?${#2}:n));};mapfile -tc1 -C q v;for((p=++n+1;p;--p));do z+=═;done;echo ╔$z╗;printf "║ %-${n}s║\n" "${v[@]}";echo ╚$z╝'< bear.txt
```
Sample run from script:
```
$ cat bear2.txt 
     (()__(()
     /       \
    ( /    \  \
     \ o o    /
     (_()_)__/ \
    / _,==.____ \
   (   |--|      )
   /\_.|__|'-.__/\_
  / (        /     \
  \  \      (      /
   )  '._____)    /
(((____.--(((____/mrf
$ ./frame< bear2.txt 
╔═══════════════════════╗
║      (()__(()         ║
║      /       \        ║
║     ( /    \  \       ║
║      \ o o    /       ║
║      (_()_)__/ \      ║
║     / _,==.____ \     ║
║    (   |--|      )    ║
║    /\_.|__|'-.__/\_   ║
║   / (        /     \  ║
║   \  \      (      /  ║
║    )  '._____)    /   ║
║ (((____.--(((____/mrf ║
╚═══════════════════════╝
```
[Answer]
# Perl, 111 characters
(score includes +5 for the interpreter flags)
```
#!/usr/bin/perl -n0 -aF\n
$n=(sort{$b<=>$a}map length,@F)[0];$l="═"x$n;
print"╔═$l═╗\n",(map{sprintf"║ %-${n}s ║\n",$_}@F),"╚═$l═╝";
```
First, we find the longest line length `$n`, by numerically sorting the lengths of all lines.
We set `$l` to be the header/footer bar to be `$n` repetitions of the horizontal frame character.
Then we print each line formatted to left-align in a field of width `$n`, sandwiched in between the frame characters.
### Result:
```
╔═══════════╗
║   |\_/|   ║
║  / @ @ \  ║
║ ( > * < ) ║
║  `>>x<<'  ║
║  /  O  \  ║
╚═══════════╝
```
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), ~~159~~ 141 bytes
```
{a[NR,1]=x=length(a[NR]=$0)
m=m<x?x:m}END{for(;i++<m+2;)t=t"═"
for(print"╔"t"╗";j++<NR;)printf"║ %-"m"s ║\n",a[j]
print"╚"t"╝"}
```
[Try it online!](https://tio.run/##SyzP/v@/OjHaL0jHMNa2wjYnNS@9JEMDJBBrq2KgyZVrm2tTYV9hlVvr6udSnZZfpGGdqa1tk6ttZK1ZYlui9GjqBCUukHBBUWYeiDtFCUROV7LOAirzC7LWBEukAcUmKqjqKuUqFSsAmTF5SjqJ0VmxXDBts8Da5irV/v@vBQJcCmBCAcoAi/0HAA "AWK – Try It Online")
Apparently `awk` can print Unicode if you can figure out how to get it in the code.
Thanks, @ceilingcat, for pointing out that my code could be rearranged to save 18 bytes.
[Answer]
## Pyth, 44 chars (58 bytes)
```
++\╔K*JhheSlR.z\═\╗jbm+\║+.[+;d;J\║.z++\╚K\╝
```
Explanation
```
++\╔K*JhheSlR.z\═\╗                          - print out the first line
           lR.z                              -        map(len, all_input())
          S                                  -       sorted(^)
         e                                   -      ^[-1]
       hh                                    -     ^+2
      J                                      -    autoassign J = ^
     *         \═                            -   ^*"═"
    K                                        -  autoassign K = ^
++\╔             \╗                          - imp_print("╔"+^+"╗")
                   jbm+\║+.[+;d;J\║.z        - print out the middle
                   jb                        - "\n".join(V)
                     m             .z        -  [V for d in all_input()]
                      +\║+       \║          -   "║"+V+"║"
                          .[   ;J            -    pad(V, " ", J)
                            +;d              -     " "+d
                                     ++\╚K\╝ - print out the end
                                     ++\╚K\╝ - imp_print("╚"+K+"╝")
```
[Try it here.](http://pyth.herokuapp.com/?code=%2B%2B%5C%E2%95%94K*JhheSlR.z%5C%E2%95%90%5C%E2%95%97jbm%2B%5C%E2%95%91%2B.[%2B%3Bd%3BJ%5C%E2%95%91.z%2B%2B%5C%E2%95%9AK%5C%E2%95%9D&input=*****%0A+***%0A++*%0A+***%0A*****&debug=0)
[Answer]
# PHP 5.3, 209 bytes
This only works using the encoding [OEM 860](https://en.wikipedia.org/wiki/Code_page_860). It is an Extended ASCII superset, used in Portuguese DOS versions. Since I'm Portuguese (and I used to love doing these "frames" in Pascal) and this is a standard encoding, I went ahead with this:
```
<?foreach($W=explode('
',$argv[1])as$v)$M=max($M,strlen($v)+2);printf("É%'Í{$M}s»
º%1\${$M}sº
%2\$s
º%1\${$M}sº
È%1\$'Í{$M}s¼",'',join('
',array_map(function($v)use($M){return str_pad(" $v ",$M);},$W)));
```
Here's the base64:
```
PD9mb3JlYWNoKCRXPWV4cGxvZGUoJwonLCRhcmd2WzFdKWFzJHYpJE09bWF4KCRNLHN0cmxlbigkdikrMik7cHJpbnRmKCLilZQlJ+KVkHskTX1z4pWXCuKVkSUxXCR7JE19c+KVkQolMlwkcwrilZElMVwkeyRNfXPilZEK4pWaJTFcJCfilZB7JE19c+KVnSIsJycsam9pbignCicsYXJyYXlfbWFwKGZ1bmN0aW9uKCR2KXVzZSgkTSl7cmV0dXJuIHN0cl9wYWQoIiAkdiAiLCRNKTt9LCRXKSkpOw==
```
This answer was based on my answer on: <https://codegolf.stackexchange.com/a/57883/14732> (the heavy lifting was all made there, just had to twitch a bit).
[Answer]
# Python 3, 119 Bytes
```
def f(x): 
 n='\n';s="║ ";e=" ║";h=(x.find(n)+2)*"═";return"╔"+h+"╗"+n+s+x.replace(n,e+n+s)+e+n+"╚"+h+"╝"
```
~~126 bytes~~
```
import sys
o=["║ %s ║\n"%j[:-1] for j in sys.stdin]
h="═"*(len(o[0])-3)
print("╔"+h+"╗\n"+"".join(o)+"╚"+h+"╝")
```
Input:
```
hello
there
  !  
```
Output:
```
╔═══════╗
║ hello ║
║ there ║
║   !   ║
╚═══════╝
```
[Answer]
# Python 2, 115 Bytes
```
def f(i):w='═'*(i.find('\n')+2);return'╔%s╗\n║ %s ║\n╚%s╝'%(w,' ║\n║ '.join(i.split('\n')),w)
```
Looks shorter than 115 here, but working file includes 3-byte UTF-8 BOM mark signature, bumping it up to 115 bytes. If you were to run it in Python 3 you wouldn't need the BOM and it'd get down to 112 bytes.
[Answer]
# C, 290 bytes
Golfed function `B`, with dependencies; takes input as null-terminated char\*
```
#define l(s) strlen(s)
p(char*s,int n){while(n--)printf(s);}
B(char*s){char*t=strtok(s,"\n");int x=l(t),z=1;while(t=strtok(0,"\n"))z++,x=l(t)>x?l(t):x;p("╔",1);p("=",x+2);p("╗\n",1);while(z--)printf("║ %s", s),p(" ",x-l(s)),p(" ║\n",1),s+=l(s)+1;p("╚",1);p("=",x+2);p("╝\n",1);}
```
Somewhat-ungolfed function in full program
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1024
// GOLF-BEGIN =>
#define l(s) strlen(s)
// since multibyte chars don't fit in char: use char* instead
void p (char*s,int n){ while(n--)printf(s); } 
void B (char *s){
    char *t = strtok(s,"\n");
    int x=l(t), z=1;
    while(t=strtok(0,"\n"))z++,x=l(t)>x?l(t):x;  
    // x is l(longest line), z is #lines
    p("╔",1);p("=",x+2);p("╗\n",1);
    while(z--)printf("║ %s", s),p(" ",x-l(s)),p(" ║\n",1),s+=l(s)+1;
    p("╚",1);p("=",x+2);p("╝\n",1);       
}
// <= GOLF-END
int main(int argc, char **argv) {
    char buffer[MAX];
    memset(buffer, 0, MAX);
    FILE *f = fopen(argv[1], "rb");
    fread(buffer, 1, MAX, f); 
    B(buffer);
    return 0;
}
```
[input](http://www.chris.com/ascii/index.php?art=objects/light%20bulbs)
```
     _.,----,._
   .:'        `:.
 .'              `.
.'                `.
:                  :
`    .'`':'`'`/    '
 `.   \  |   /   ,'
   \   \ |  /   /
    `\_..,,.._/'
     {`'-,_`'-}
     {`'-,_`'-}
     {`'-,_`'-}
      `YXXXXY'
        ~^^~
```
output
```
╔======================╗
║      _.,----,._      ║
║    .:'        `:.    ║
║  .'              `.  ║
║ .'                `. ║
║ :                  : ║
║ `    .'`':'`'`/    ' ║
║  `.   \  |   /   ,'  ║
║    \   \ |  /   /    ║
║     `\_..,,.._/'     ║
║      {`'-,_`'-}      ║
║      {`'-,_`'-}      ║
║      {`'-,_`'-}      ║
║       `YXXXXY'       ║
║         ~^^~         ║
╚======================╝
```
C golfing tips appreciated!
]