-
Notifications
You must be signed in to change notification settings - Fork 0
/
thumbGrande.php
53 lines (49 loc) · 1.41 KB
/
thumbGrande.php
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
43
44
45
46
47
48
49
50
51
52
53
<?php
$fuente = @imagecreatefromjpeg(str_replace(" ", "%20", $_GET['foto']));
if (!$fuente) {
$fuente = @imagecreatefromgif(str_replace(" ", "%20", $_GET['foto']));
}
if (!$fuente) {
$fuente = @imagecreatefrompng(str_replace(" ", "%20", $_GET['foto']));
}
$imgAncho = imagesx($fuente);
$imgAlto = imagesy($fuente);
$canvasAncho = 600;
$canvasAlto = 400;
$max_an = 600;
$max_al = 400;
$x = $imgAncho;
$y = $imgAlto;
if ($imgAncho > $max_an || $imgAlto > $max_al) {
if ($imgAlto >= $imgAncho) {
$y = $max_al;
$ratio = $y / $imgAlto;
$x = $imgAncho * $ratio;
if ($x > $max_an) {
$x1 = $max_an;
$ratio = $x1 / $x;
$y1 = $y * $ratio;
$x = $x1;
$y = $y1;
}
} else {
$x = $max_an;
$ratio = $x / $imgAncho;
$y = $imgAlto * $ratio;
if ($y > $max_al) {
$y1 = $max_al;
$ratio = $y1 / $y;
$x1 = $x * $ratio;
$x = $x1;
$y = $y1;
}
}
}
$canvas = imagecreatetruecolor($canvasAncho, $canvasAlto);
$blanco = imagecolorallocate($canvas, 255, 255, 255);
imagefill($canvas, 0, 0, $blanco);
$xCambasI = (int) (($canvasAncho - $x) / 2);
$yCambasI = (int) (($canvasAlto - $y) / 2);
ImageCopyResampled($canvas, $fuente, $xCambasI, $yCambasI, 0, 0, $x, $y, $imgAncho, $imgAlto);
header("Content-type: image/jpeg");
imageJpeg($canvas, "", 100);