-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
58 lines (43 loc) · 1.75 KB
/
test.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
54
55
56
57
<?php
function insertScaledText(&$img, $x, $y, $font, $size, $text) {
// create temp image and insert text
$tmp = imagecreate(2048,1536);
$white = imagecolorallocate($tmp, 255, 255, 255);
$col = imagecolorallocate($tmp, 0, 0, 0);
imagefill($tmp, 0, 0, $white);
imagettftext($tmp, $size, 0, 0, 100, $col, $font, $text);
Header('Content-Type: image/jpeg');
imagejpeg($tmp);
die();
$dimensions = imagettfbbox($size, 0, $font, $text);
// scale image down
$scl = imagecreate(1024,768);
imagecopyresampled($scl, $tmp, 0,0,0,0,1024, 768,2048,1536);
// copy text rectangle onto original image
imagecopy($img, $scl, $x, $y, 0, 0, $dimensions[2], $dimensions[3]);
// free memory
imagedestroy($tmp);
imagedestroy($scl);
}
$img = @imagecreatetruecolor(1024, 768) or die('Unable to create GD-stream');
// some colors
$color['white'] = imagecolorallocatealpha($img, 255, 255, 255, 127);
$color['black'] = imagecolorallocatealpha($img, 0, 0, 0, 127);
// fill image with white
imagefill($img, 0, 0, $color['white']);
// import title image:
$img2 = imagecreatefromjpeg(dirname(__FILE__).'/test/test.jpg');
// impose on the background image
imagecopy($img, $img2, 0, 0, 0, 0, 1024, 507);
// write first text
//imagettftext ($img, 43, 0, 40, 600, $color['black'], dirname(__FILE__).'/fonts/OpenSans-Regular.ttf', 'Sonntag, 15:00 Uhr');
insertScaledText($img, 40, 600, dirname(__FILE__).'/fonts/OpenSans-Regular.ttf', 43, 'Sonntag, 15:00 Uhr');
// write second text
//imagettftext ($img, 43, 0, 40, 680, $color['black'], dirname(__FILE__).'/fonts/OpenSans-ExtraBold.ttf', "Meet the Pastor\rMeet the Pastor");
imagealphablending($img, true);
imagesavealpha($img, true);
Header('Content-Type: image/jpeg');
imagejpeg($img);
imagedestroy($img);
imagedestroy($img2);
exit;