Scripts

Post-it briefje

Met dit script kun je Post-it briefjes maken. Dit script maakt gebruik van GD library. Voorbeeld In browser voorbeeld In browser voorbeeld Lege post-it note Opslaan als Font http://easy-upload.nl/f/GJLTPCrp Parameters MESSAGE = Het bericht weer te geven FROM = Groet onderaan het briefje D = Aantal graden (degrees) dat het briefje moet draaien (letop: de post-it note heeft een rare achtergrond zoals je ziet en is bedoeld voor een witte achtergrond.)

post-it.php
<?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);

Reacties

0
Nog geen reacties.