Generate JPG logos too. PDF uses JPG internally, so for TCPDF it's handy

to have a JPG logo around (TCPDF takes FOREVER to generate a JPG
internally, because it uses GD.  :p  )
This commit is contained in:
dave 2010-03-31 05:52:52 +00:00
parent c42748989b
commit 2332d89736
2 changed files with 51 additions and 13 deletions

View File

@ -22,22 +22,35 @@
*/
?>
<?
require("../common.inc.php");
require_once("../user.inc.php");
user_auth_required('committee', 'config');
send_header("Fair Logo Image",
require_once('../common.inc.php');
require_once('../user.inc.php');
user_auth_required('committee', 'config');
send_header("Fair Logo Image",
array('Committee Main' => 'committee_main.php',
'SFIAB Configuration' => 'config/index.php'),
"images");
if($_POST['action']=="addimage")
{
if($_FILES['image']['error']==UPLOAD_ERR_OK)
{
if($_POST['action']=="addimage") {
if($_FILES['image']['error']==UPLOAD_ERR_OK) {
//make sure its a JPEG
$imagesize=getimagesize($_FILES['image']['tmp_name']);
if($imagesize[2]==1 || $imagesize[2]==2 || $imagesize[2]==3) // GIF or JPG or PNG
{
/* Here's how to do it with GD, if GD didn't absolutely suck at
* resizing an image (thought I'd try it again, Mar30, 2010, still sucks).
$image_data = file_get_contents($_FILES['image']['tmp_name']);
$image = imagecreatefromstring($image_data);
$w = imagesx($image);
$h = imagesy($image);
$ratio = $h / $w;
$image100 = imagecreate(100, $ratio * 100);
imagecopyresampled($image100, $image, 0, 0, 0, 0, 100, $ratio * 100, $w, $h);
imagejpeg($image100, "../data/logo-100.jpg");*/
echo notice(i18n("Creating sized logo files:<br />&nbsp;logo-100.gif<br />&nbsp;logo-200.gif<br />&nbsp;logo-500.gif<br />&nbsp;logo.gif"));
//Make the gif's
system("convert -resize 100 \"".$_FILES['image']['tmp_name']."\" ../data/logo-100.gif");
@ -61,6 +74,18 @@ if($_POST['action']=="addimage")
echo happy(i18n("PNG Images successfully created"));
else
echo error(i18n("Error creating PNG Image files. Make sure 'convert' binary is in your path, and that 'system' function can be used"));
echo notice(i18n("Creating sized logo files:<br />&nbsp;logo-100.jpg<br />&nbsp;logo-200.jpg<br />&nbsp;logo-500.jpg<br />&nbsp;logo.jpg"));
//make some PNG's as well
system("convert -resize 100 \"".$_FILES['image']['tmp_name']."\" ../data/logo-100.jpg");
system("convert -resize 200 \"".$_FILES['image']['tmp_name']."\" ../data/logo-200.jpg");
system("convert -resize 500 \"".$_FILES['image']['tmp_name']."\" ../data/logo-500.jpg");
system("convert \"".$_FILES['image']['tmp_name']."\" ../data/logo.jpg");
if(file_exists("../data/logo-100.jpg") && file_exists("../data/logo-200.jpg") && file_exists("../data/logo-500.jpg") && file_exists("../data/logo.jpg"))
echo happy(i18n("JPG Images successfully created"));
else
echo error(i18n("Error creating JPG Image files. Make sure 'convert' binary is in your path, and that 'system' function can be used"));
}
else
{
@ -113,6 +138,18 @@ if($_POST['action']=="delimage") {
echo "<a target=\"_blank\" href=\"../data/logo-500.png\">500 Pixel width</a><br />";
echo "</td></tr>";
}
if(file_exists("../data/logo.jpg"))
{
echo "<tr><td colspan=\"2\">".i18n("JPG Images")."</td></tr>";
echo "<tr><td>";
echo "<img src=\"../data/logo-100.jpg\" border=\"0\">";
echo "</td><td>";
echo "<a target=\"_blank\" href=\"../data/logo.jpg\">",i18n("Original size")."</a><br />";
echo "<a target=\"_blank\" href=\"../data/logo-100.jpg\">".i18n("100 Pixel width")."</a><br />";
echo "<a target=\"_blank\" href=\"../data/logo-200.jpg\">".i18n("200 Pixel width")."</a><br />";
echo "<a target=\"_blank\" href=\"../data/logo-500.jpg\">500 Pixel width</a><br />";
echo "</td></tr>";
}
echo "<tr><td colspan=2>";
echo "<input type=\"file\" name=\"image\">";
echo "<input type=\"submit\" value=\"".i18n("Upload Logo")."\" />\n";

View File

@ -54,11 +54,12 @@ class pdf extends TCPDF {
$this->SetSubject($report_name);
$this->SetKeywords('');
/* Set default header data (K_PATH_IMAGES/logo.png, 16mm wide,
header, name */
$this->SetHeaderData('logo.png', 16 /* mm */,
i18n($config['fairname']),
i18n($report_name));
/* Set default header data (K_PATH_IMAGES/logo-500.jpg, 16mm wide, header, name)
* PDFs use JPG internally, so we should feed it a jpeg, if we dont', tcpdf will
* convert it to a jpg anyway, and that takes FOREVER if there's lots of
* pages/labels.*/
$this->SetHeaderData('logo-500.jpg', 16 /* mm */,
i18n($config['fairname']), i18n($report_name));
// set header and footer fonts
$this->setHeaderFont(Array('helvetica', '', 14));