commit
737d223d21
After Width: | Height: | Size: 66 KiB |
After Width: | Height: | Size: 60 KiB |
@ -0,0 +1,74 @@ |
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<title>TDF Badge</title> |
||||
<style> |
||||
body { |
||||
display: flex; |
||||
align-items: center; |
||||
justify-content: center; |
||||
height: 100vh; |
||||
margin: 0; |
||||
padding: 0; |
||||
} |
||||
|
||||
#container { |
||||
position: relative; |
||||
} |
||||
|
||||
#badge { |
||||
width: 100%; |
||||
display: block; |
||||
margin: 0 auto; |
||||
} |
||||
|
||||
#name-input { |
||||
position: absolute; |
||||
top: 94px; |
||||
width: 324px; |
||||
height: 92px; |
||||
font-size: 62px; |
||||
text-align: left; |
||||
margin-left: 123px; |
||||
opacity: 0.65; |
||||
font-family: inherit; |
||||
} |
||||
|
||||
#pronouns-input { |
||||
position: absolute; |
||||
bottom: 87px; |
||||
right: 17px; |
||||
width: 165px; |
||||
font-size: 20px; |
||||
opacity: 0.65; |
||||
font-family: inherit; |
||||
} |
||||
|
||||
#print-button { |
||||
display: block; |
||||
margin: 20px auto; |
||||
} |
||||
|
||||
@font-face { |
||||
font-family: "ComicCode"; |
||||
src: url('ComicCodeMedium.otf') format("opentype"); |
||||
} |
||||
|
||||
#preview { |
||||
font-family: "ComicCode"; |
||||
} |
||||
</style> |
||||
</head> |
||||
<body> |
||||
<div id="container"> |
||||
<form action="print_badge.php" method="GET"> |
||||
<div id="preview"> |
||||
<img id="badge" src="TDF/Badge.png" alt="Badge"> |
||||
<input name="name" id="name-input" type="text" placeholder="Name"> |
||||
<input name="pronouns" id="pronouns-input" type="text" placeholder="pronouns"> |
||||
</div> |
||||
<input type="submit" id="print-button" value="Print" > |
||||
</form> |
||||
</div> |
||||
</body> |
||||
</html> |
@ -0,0 +1,90 @@ |
||||
<?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> |
Loading…
Reference in new issue