You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							90 lines
						
					
					
						
							3.2 KiB
						
					
					
				
			
		
		
	
	
							90 lines
						
					
					
						
							3.2 KiB
						
					
					
				<?php
 | 
						|
if (extension_loaded('gd') && function_exists('gd_info')) {
 | 
						|
	if (isset($_GET['name'])) {
 | 
						|
	    $NAME = $_GET['name']; 
 | 
						|
	    $PRONOUNS= $_GET['pronouns'];
 | 
						|
	    $NAME_FONT_SIZE = 62;
 | 
						|
	    $PRONOUN_FONT_SIZE=20;
 | 
						|
	    $print_dev = '/dev/usb/lp0';
 | 
						|
	    $debug = false;
 | 
						|
	
 | 
						|
	    $badge = imagecreatefrompng('TDF/Badge.png');
 | 
						|
	    $written_badge_path = "uploads/badge";
 | 
						|
	    $written_badge_ext  = ".png";
 | 
						|
	    $badge_width = imagesx($badge);
 | 
						|
	    $badge_height= imagesy($badge);
 | 
						|
	    $margin_name_left = 126;
 | 
						|
	    $margin_name_top  = 94;
 | 
						|
	    $margin_pron_left = 284;
 | 
						|
	    $margin_pron_top  = 246;
 | 
						|
	    $name_field_width = 330;
 | 
						|
	    $name_field_height= 98;
 | 
						|
	    $pron_field_width = 172;
 | 
						|
	    $pron_field_height= 32;
 | 
						|
 | 
						|
	    $font_color = imagecolorexact($badge, 0, 0, 0);
 | 
						|
	    putenv('GDFONTPATH=' . realpath('.'));
 | 
						|
	    $font_path = "ComicCodeMedium.otf";
 | 
						|
	    $font = imageloadfont($font_path);
 | 
						|
 | 
						|
	    # adjust font size s.t. the entire name fits into the name box 
 | 
						|
	    $namebox = imagettfbbox($NAME_FONT_SIZE, 0, $font_path, $NAME);	    
 | 
						|
	    while (($namebox[2] - $namebox[0]) > $name_field_width) {
 | 
						|
		    $NAME_FONT_SIZE = $NAME_FONT_SIZE - 1;
 | 
						|
		    $namebox = imagettfbbox($NAME_FONT_SIZE, 0, $font_path, $NAME);
 | 
						|
	    }
 | 
						|
 | 
						|
	    # center the name text box
 | 
						|
	    $namebox_h = $namebox[1] - $namebox[7]; # y of down left edge - y of up left edge
 | 
						|
	    $namebox_y = $margin_name_top + ($name_field_height/2) + ($namebox_h/2); 
 | 
						|
	    imagefttext($badge, $NAME_FONT_SIZE, 0, $margin_name_left, $namebox_y, $font_color, $font_path, $NAME);
 | 
						|
 | 
						|
	    # adjust font size for the pronouns
 | 
						|
	    $pronbox = imagettfbbox($PRONOUN_FONT_SIZE, 0, $font_path, $PRONOUNS);	    
 | 
						|
	    while (($pronbox[2] - $pronbox[0]) > $pron_field_width) {
 | 
						|
	    	$PRONOUN_FONT_SIZE = $PRONOUN_FONT_SIZE - 1;
 | 
						|
	    	$pronbox = imagettfbbox($PRONOUN_FONT_SIZE, 0, $font_path, $PRONOUNS); 
 | 
						|
	    }
 | 
						|
 | 
						|
	    # center the pronoun text box
 | 
						|
	    $pronbox_h = $pronbox[1] - $pronbox[7];
 | 
						|
	    $pronbox_y = $margin_pron_top + ($pron_field_height/2) + ($pronbox_h/2);
 | 
						|
	    imagefttext($badge, $PRONOUN_FONT_SIZE, 0, $margin_pron_left, $pronbox_y, $font_color, $font_path, $PRONOUNS);
 | 
						|
 | 
						|
	    # display image	    
 | 
						|
	    //header('Content-Type: image/png');
 | 
						|
	    imagefilter($badge, IMG_FILTER_GRAYSCALE);
 | 
						|
	    if(imagepng($badge, $written_badge_path.$written_badge_ext)) {
 | 
						|
	   	imagedestroy($badge);
 | 
						|
		# convert and print image
 | 
						|
		$printable_file = $written_badge_path."_".$written_badge_ext;
 | 
						|
		$cmd_convert = "convert ".$written_badge_path.$written_badge_ext." -background white -alpha remove -compose copy_opacity -resize x720 -monochrome ".$printable_file;
 | 
						|
		#$cmd_convert = "convert uploads/badge.png -background white -alpha remove -compose copy_opacity -resize x720 -monochrome uploads/badge_.png";
 | 
						|
		#$cmd_print   = "./ql570 /dev/usb/lp0 w uploads/badge_.png";
 | 
						|
		$cmd_print   = "./ql570 ".$print_dev." w ".$printable_file;
 | 
						|
		$output_convert = shell_exec($cmd_convert);
 | 
						|
		$output_print   = shell_exec($cmd_print);
 | 
						|
	    } else {
 | 
						|
	    	echo "Badge could not be created";
 | 
						|
	    }
 | 
						|
	} else {
 | 
						|
		echo "No name has been set";
 | 
						|
	}
 | 
						|
}
 | 
						|
else {
 | 
						|
    echo "GD library is not installed";
 | 
						|
}
 | 
						|
if($debug == false) {
 | 
						|
	header('Location: http://'.$_SERVER['HTTP_HOST']);
 | 
						|
}
 | 
						|
?>
 | 
						|
<!DOCTYPE html>
 | 
						|
<html>
 | 
						|
<head>
 | 
						|
<title>TDF Badges</title>
 | 
						|
</head>
 | 
						|
<body>
 | 
						|
<center>
 | 
						|
	<img src='uploads/badge_.png'></img>
 | 
						|
</body>
 | 
						|
</html>
 | 
						|
 |