function copy_img img copy_path _SERVER DOCUMENT_ROOT copy png if isse

 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
function copy_img($img)
{
$copy_path = $_SERVER['DOCUMENT_ROOT'] . '/copy.png';
if (isset($copy_path) && $copy_path != null && $copy = @imagecreatefromstring(file_get_contents($copy_path)))
{
$img_x = imagesx($img);
$img_y = imagesy($img);
$copy_x = imagesx($copy);
$copy_y = imagesy($copy);
$w = intval(min($img_x / 2.5, $copy_x, 128));
$h = intval(min($img_y / 2.5, $copy_y, 64));
$x_ratio = $w / $copy_x;
$y_ratio = $h / $copy_y;
if (($copy_x <= $w) && ($img_y <= $h))
{
$dstW = $copy_x;
$dstH = $copy_y;
}
elseif (($x_ratio * $copy_y) < $h)
{
$dstH = ceil($x_ratio * $copy_y);
$dstW = $w;
}
else
{
$dstW = ceil($y_ratio * $copy_x);
$dstH = $h;
}
imagecopyresampled($img, $copy, $img_x - $dstW, $img_y - $dstH, 0, 0, $dstW, $dstH, $copy_x, $copy_y);
}
return $img;
}