-
Notifications
You must be signed in to change notification settings - Fork 0
/
mm_image.inc
42 lines (37 loc) · 856 Bytes
/
mm_image.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
// read image $src, write middle square as NxN image to $dest
//
function extract_middle_square($src, $dst, $size) {
[$w, $h, $type] = getimagesize($src);
if ($w > $h) {
$src_offx = ($w-$h)/2;
$src_offy = 0;
$src_size = $h;
} else {
$src_offx = 0;
$src_offy = ($h-$w)/2;
$src_size = $w;
}
switch ($type) {
case 1:
$src_img = imageCreateFromGif($src);
break;
case 2:
$src_img = imageCreateFromJpeg($src);
break;
case 3:
$src_img = imageCreateFromPng($src);
break;
}
$dst_img = imageCreateTrueColor($size, $size);
imagecopyresampled(
$dst_img,
$src_img,
0,0,
$src_offx, $src_offy,
$size, $size,
$src_size, $src_size
);
ImageJPEG($dst_img, $dst);
}
?>