post-it.php

Gesponsorde koppelingen

PHP script bestanden

  1. post-it.php

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
 
// config
$size         = 14;
$maxwidth     = 192;
$line         = 3;
$text          = ($_GET['message']) ? $_GET['message'] : 'message parameter missing';
$from          = ($_GET['from']) ? $_GET['from'] : 'from parameter missing';

$xposdefault    = 15;
$xpos         = $xposdefault;
$font         = "fonts/DakotaRegular.ttf";
$lineheight       = 0;
$rotation     =  $_GET['d'];

// replace j
$from = str_replace("j", "j ", $from); // the J in the font is bugging, notice the draw line (imagettftext) later in the script where is a replacement again.

// get background

$im = imagecreatefrompng("images/post-it.png");

// prepare colors
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
$grey = imagecolorallocate($im, 0xCC, 0xCC, 0xCC);
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);

// calculate total width of every word
$words = explode(" ", $text);
for($i = 0; $i < count($words); $i++){

    // add space to word
    if($words[$i] != "j"){
    $words[$i] = $words[$i]." ";
    }

    
    // save width
    $wordwidth[$i] = imageftbbox($size, 0, $font, $words[$i]);
    
    // save highest lineheight
    if(($wordwidth[$i][7]*-1) > $lineheight) $lineheight = ($wordwidth[$i][7]*-1);
    
}


// calculate width of space
$spacewidth = imageftbbox($size, 0, $font, " ");

// draw words
for($i = 0; $i < count($words); $i++){

    // draw
    imagettftext($im, $size, 0, $xpos, $line*$lineheight, $black, $font, str_replace("j","j ",$words[$i]));
    
    // check line
    if(($xpos + $wordwidth[$i][4] + $wordwidth[$i+1][4]) > $maxwidth){
        $line += 1.5;
        $xpos = $xposdefault;  
    }
else{
        $xpos += $wordwidth[$i][4];
    }
        
}


// get greeting dimensions
$fromwidth = imageftbbox($size-4, 0, $font, $from);

// draw greeting
imagettftext($im, $size-4, 0, 175-$fromwidth[4], 180, $black, $font, $from);


// allow transparancy
imagealphablending($im, false);
imagesavealpha($im, true);

// header
header("Content-type: image/png");

// output image
$rotate = imagerotate($im, $rotation, imagecolorallocate($im, 255, 255, 255));
imagesavealpha($rotate, true);
imagealphablending($rotate, false);
imagepng($rotate);

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.