Issue configuring TCPDF on xampp - php

I am currently trying to get tcpdf working on my website. I am using xampp as a localhost, but cannot seem to get the config files working correctly. I am almost certain my paths are pointing to the right directory in tcpdf_config.php but when I try and run a script on my email.php page, it is displaying the error shown below. I have tried playing around with pointing to the file/s in a number of ways, but to no avail.
When i navigate to the examples given in the TCPDF folder, they load and work fine, so not sure why i cannot get this page work. Any help much appreciated!
i have tcpdf installed in my xampp directory as follows:
C:/xampp/htdocs/projects/ibill_v3/tcpdf
tcpdf_config.php
<?php
//============================================================+
// File name : tcpdf_config.php
// Begin : 2004-06-11
// Last Update : 2014-12-11
//
// Description : Configuration file for TCPDF.
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info#tecnick.com
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
// -------------------------------------------------------------------
// Copyright (C) 2004-2014 Nicola Asuni - Tecnick.com LTD
//
// This file is part of TCPDF software library.
//
// TCPDF is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// TCPDF is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with TCPDF. If not, see <http://www.gnu.org/licenses/>.
//
// See LICENSE.TXT file for more information.
//============================================================+
/**
* Configuration file for TCPDF.
* #author Nicola Asuni
* #package com.tecnick.tcpdf
* #version 4.9.005
* #since 2004-10-27
*/
// IMPORTANT:
// If you define the constant K_TCPDF_EXTERNAL_CONFIG, all the following settings will be ignored.
// If you use the tcpdf_autoconfig.php, then you can overwrite some values here.
/**
* Installation path (/var/www/tcpdf/).
* By default it is automatically calculated but you can also set it as a fixed string to improve performances.
*/
define ('K_PATH_MAIN', 'C:/xampp/htdocs/projects/ibill_v3/tcpdf');
/**
* URL path to tcpdf installation folder (http://localhost/tcpdf/).
* By default it is automatically set but you can also set it as a fixed string to improve performances.
*/
define ('K_PATH_URL', 'C:/xampp/htdocs/projects/ibill_v3/tcpdf');
/**
* Path for PDF fonts.
* By default it is automatically set but you can also set it as a fixed string to improve performances.
*/
//define ('K_PATH_FONTS', K_PATH_MAIN.'fonts/');
/**
* Default images directory.
* By default it is automatically set but you can also set it as a fixed string to improve performances.
*/
define ('K_PATH_IMAGES', 'C:/xampp/htdocs/projects/ibill_v3/tcpdf/fonts');
/**
* Deafult image logo used be the default Header() method.
* Please set here your own logo or an empty string to disable it.
*/
//define ('PDF_HEADER_LOGO', '');
/**
* Header logo image width in user units.
*/
//define ('PDF_HEADER_LOGO_WIDTH', 0);
/**
* Cache directory for temporary files (full path).
*/
//define ('K_PATH_CACHE', '/tmp/');
/**
* Generic name for a blank image.
*/
define ('K_BLANK_IMAGE', '_blank.png');
/**
* Page format.
*/
define ('PDF_PAGE_FORMAT', 'A4');
/**
* Page orientation (P=portrait, L=landscape).
*/
define ('PDF_PAGE_ORIENTATION', 'P');
/**
* Document creator.
*/
define ('PDF_CREATOR', 'TCPDF');
/**
* Document author.
*/
define ('PDF_AUTHOR', 'TCPDF');
/**
* Header title.
*/
define ('PDF_HEADER_TITLE', 'TCPDF Example');
/**
* Header description string.
*/
define ('PDF_HEADER_STRING', "by Nicola Asuni - Tecnick.com\nwww.tcpdf.org");
/**
* Document unit of measure [pt=point, mm=millimeter, cm=centimeter, in=inch].
*/
define ('PDF_UNIT', 'mm');
/**
* Header margin.
*/
define ('PDF_MARGIN_HEADER', 5);
/**
* Footer margin.
*/
define ('PDF_MARGIN_FOOTER', 10);
/**
* Top margin.
*/
define ('PDF_MARGIN_TOP', 27);
/**
* Bottom margin.
*/
define ('PDF_MARGIN_BOTTOM', 25);
/**
* Left margin.
*/
define ('PDF_MARGIN_LEFT', 15);
/**
* Right margin.
*/
define ('PDF_MARGIN_RIGHT', 15);
/**
* Default main font name.
*/
define ('PDF_FONT_NAME_MAIN', 'helvetica');
/**
* Default main font size.
*/
define ('PDF_FONT_SIZE_MAIN', 10);
/**
* Default data font name.
*/
define ('PDF_FONT_NAME_DATA', 'helvetica');
/**
* Default data font size.
*/
define ('PDF_FONT_SIZE_DATA', 8);
/**
* Default monospaced font name.
*/
define ('PDF_FONT_MONOSPACED', 'courier');
/**
* Ratio used to adjust the conversion of pixels to user units.
*/
define ('PDF_IMAGE_SCALE_RATIO', 1.25);
/**
* Magnification factor for titles.
*/
define('HEAD_MAGNIFICATION', 1.1);
/**
* Height of cell respect font height.
*/
define('K_CELL_HEIGHT_RATIO', 1.25);
/**
* Title magnification respect main font size.
*/
define('K_TITLE_MAGNIFICATION', 1.3);
/**
* Reduction factor for small font.
*/
define('K_SMALL_RATIO', 2/3);
/**
* Set to true to enable the special procedure used to avoid the overlappind of symbols on Thai language.
*/
define('K_THAI_TOPCHARS', true);
/**
* If true allows to call TCPDF methods using HTML syntax
* IMPORTANT: For security reason, disable this feature if you are printing user HTML content.
*/
define('K_TCPDF_CALLS_IN_HTML', false);
/**
* If true and PHP version is greater than 5, then the Error() method throw new exception instead of terminating the execution.
*/
define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
/**
* Default timezone for datetime functions
*/
define('K_TIMEZONE', 'UTC');
//============================================================+
// END OF FILE
//============================================================+
email.php
<?php
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
class ashPDF extends TCPDF {
public function Header() {
$this->setJPEGQuality(90);
$this->Image('logo.png', 62, 36, 72, 0, 'PNG', '/projects/ibill_v3/img/ibill logo.png');
}
public function Footer() {
$this->SetY(-15);
$this->SetFont(PDF_FONT_NAME_MAIN, 'I', 8);
$this->Cell(0, 10, 'php.refulz.com – Web Developer’s Blog', 0, false, 'C');
}
}
$pdf = new ashPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// $pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('ash PHP');
$pdf->SetTitle('Fisrt PDF Document using TCPDF');
$pdf->SetSubject('ash PDF Example');
$pdf->SetKeywords('ash, TCPDF, PDF');
// add a page
$pdf->AddPage();
$col = 72; // Column size
$wideCol = 3 * $col; // Description Column
$line = 18; // Line height
// Table header
$pdf->SetFont( '', 'b' );
$pdf->Cell( $col, $line, 'S. No.', 1, 0, 'L' );
$pdf->Cell( $wideCol, $line, 'Task', 1, 0, 'L' );
$pdf->Cell( $col, $line, 'Time', 1, 0, 'R' );
$pdf->Ln(); // Adds Line break
// Table content beings here
$pdf->SetFont( '', '' ); // two parameters accept font-family and style. Passing blank sets default values
$counter = 1; // Setting counter for S. No. column
foreach( $this->taskData['items'] as $item ) {
$pdf->Cell( $col, $line, $counter, 1, 0, 'L' );
$pdf->Cell( $wideCol, $line, $item[0], 1, 0, 'L' );
$pdf->Cell( $col, $line, $item[1], 1, 0, 'R' );
$pdf->Ln();
$counter++;
}
// Output the PDF document.
$pdf->Output( 'Tasksheet.pdf', 'D' );
?>
Error Messages when trying to execute email.php:
Warning: require_once(tcpdf/config/lang/eng.php): failed to open stream: No such file or directory in C:\xampp\htdocs\projects\ibill_v3\html\email.php on line 2
Fatal error: require_once(): Failed opening required 'tcpdf/config/lang/eng.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\projects\ibill_v3\html\email.php on line 2

Related

Database error: Running CodeIgniter program in Wampserver

I'm trying to run a code built with PHP's framework CodeIgniter in another computer, and I've put the program folder in Wampserver's C:/wamp/www folder, but when I open the program in "localhost/program", I get the following error messages:
A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (HY000/1045): Access denied for user
''#'localhost' (using password: NO)
Filename: mysqli/mysqli_driver.php
Line Number: 201
Backtrace:
File: C:\wamp64\www\program\application\controllers\Home.php
Line: 9
Function: __construct
File: C:\wamp64\www\program\index.php
Line: 315
Function: require_once
That's the file the error are mentioning:
Home.php:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
//print_r($this->session->userdata);
//print_r($teste);
$dados = array(
'funcao' =>'index',
'controller' => 'simplex'
);
if (!empty($this->session->userdata('variavel'))) {
$this->session->unset_userdata('variavel');
$this->session->unset_userdata('restricao');
}
$this->template->load('template/template', 'home/home', $dados);
}
public function teste()
{
//print_r($this->session->userdata);
//print_r($teste);
$dados = array(
'funcao' =>'index',
'controller' => 'simplex'
);
$this->template->load('template/template', 'home/teste', $dados);
}
}
index.php:
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* #package CodeIgniter
* #author EllisLab Dev Team
* #copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* #copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* #license http://opensource.org/licenses/MIT MIT License
* #link https://codeigniter.com
* #since Version 1.0.0
* #filesource
*/
/*
*---------------------------------------------------------------
* APPLICATION ENVIRONMENT
*---------------------------------------------------------------
*
* You can load different configurations depending on your
* current environment. Setting the environment also influences
* things like logging and error reporting.
*
* This can be set to anything, but default usage is:
*
* development
* testing
* production
*
* NOTE: If you change these, also change the error_reporting() code below
*/
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
/*
*---------------------------------------------------------------
* ERROR REPORTING
*---------------------------------------------------------------
*
* Different environments will require different levels of error reporting.
* By default development will show errors but testing and live will hide them.
*/
switch (ENVIRONMENT)
{
case 'development':
error_reporting(-1);
ini_set('display_errors', 1);
break;
case 'testing':
case 'production':
ini_set('display_errors', 0);
if (version_compare(PHP_VERSION, '5.3', '>='))
{
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
}
else
{
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
}
break;
default:
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'The application environment is not set correctly.';
exit(1); // EXIT_ERROR
}
/*
*---------------------------------------------------------------
* SYSTEM DIRECTORY NAME
*---------------------------------------------------------------
*
* This variable must contain the name of your "system" directory.
* Set the path if it is not in the same directory as this file.
*/
$system_path = 'system';
/*
*---------------------------------------------------------------
* APPLICATION DIRECTORY NAME
*---------------------------------------------------------------
*
* If you want this front controller to use a different "application"
* directory than the default one you can set its name here. The directory
* can also be renamed or relocated anywhere on your server. If you do,
* use an absolute (full) server path.
* For more info please see the user guide:
*
* https://codeigniter.com/user_guide/general/managing_apps.html
*
* NO TRAILING SLASH!
*/
$application_folder = 'application';
/*
*---------------------------------------------------------------
* VIEW DIRECTORY NAME
*---------------------------------------------------------------
*
* If you want to move the view directory out of the application
* directory, set the path to it here. The directory can be renamed
* and relocated anywhere on your server. If blank, it will default
* to the standard location inside your application directory.
* If you do move this, use an absolute (full) server path.
*
* NO TRAILING SLASH!
*/
$view_folder = '';
/*
* --------------------------------------------------------------------
* DEFAULT CONTROLLER
* --------------------------------------------------------------------
*
* Normally you will set your default controller in the routes.php file.
* You can, however, force a custom routing by hard-coding a
* specific controller class/function here. For most applications, you
* WILL NOT set your routing here, but it's an option for those
* special instances where you might want to override the standard
* routing in a specific front controller that shares a common CI installation.
*
* IMPORTANT: If you set the routing here, NO OTHER controller will be
* callable. In essence, this preference limits your application to ONE
* specific controller. Leave the function name blank if you need
* to call functions dynamically via the URI.
*
* Un-comment the $routing array below to use this feature
*/
// The directory name, relative to the "controllers" directory. Leave blank
// if your controller is not in a sub-directory within the "controllers" one
// $routing['directory'] = '';
// The controller class file name. Example: mycontroller
// $routing['controller'] = '';
// The controller function you wish to be called.
// $routing['function'] = '';
/*
* -------------------------------------------------------------------
* CUSTOM CONFIG VALUES
* -------------------------------------------------------------------
*
* The $assign_to_config array below will be passed dynamically to the
* config class when initialized. This allows you to set custom config
* items or override any default config values found in the config.php file.
* This can be handy as it permits you to share one application between
* multiple front controller files, with each file containing different
* config values.
*
* Un-comment the $assign_to_config array below to use this feature
*/
// $assign_to_config['name_of_config_item'] = 'value of config item';
// --------------------------------------------------------------------
// END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE
// --------------------------------------------------------------------
/*
* ---------------------------------------------------------------
* Resolve the system path for increased reliability
* ---------------------------------------------------------------
*/
// Set the current directory correctly for CLI requests
if (defined('STDIN'))
{
chdir(dirname(__FILE__));
}
if (($_temp = realpath($system_path)) !== FALSE)
{
$system_path = $_temp.DIRECTORY_SEPARATOR;
}
else
{
// Ensure there's a trailing slash
$system_path = strtr(
rtrim($system_path, '/\\'),
'/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
).DIRECTORY_SEPARATOR;
}
// Is the system path correct?
if ( ! is_dir($system_path))
{
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME);
exit(3); // EXIT_CONFIG
}
/*
* -------------------------------------------------------------------
* Now that we know the path, set the main path constants
* -------------------------------------------------------------------
*/
// The name of THIS file
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
// Path to the system directory
define('BASEPATH', $system_path);
// Path to the front controller (this file) directory
define('FCPATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
// Name of the "system" directory
define('SYSDIR', basename(BASEPATH));
// The path to the "application" directory
if (is_dir($application_folder))
{
if (($_temp = realpath($application_folder)) !== FALSE)
{
$application_folder = $_temp;
}
else
{
$application_folder = strtr(
rtrim($application_folder, '/\\'),
'/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
);
}
}
elseif (is_dir(BASEPATH.$application_folder.DIRECTORY_SEPARATOR))
{
$application_folder = BASEPATH.strtr(
trim($application_folder, '/\\'),
'/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
);
}
else
{
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF;
exit(3); // EXIT_CONFIG
}
define('APPPATH', $application_folder.DIRECTORY_SEPARATOR);
// The path to the "views" directory
if ( ! isset($view_folder[0]) && is_dir(APPPATH.'views'.DIRECTORY_SEPARATOR))
{
$view_folder = APPPATH.'views';
}
elseif (is_dir($view_folder))
{
if (($_temp = realpath($view_folder)) !== FALSE)
{
$view_folder = $_temp;
}
else
{
$view_folder = strtr(
rtrim($view_folder, '/\\'),
'/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
);
}
}
elseif (is_dir(APPPATH.$view_folder.DIRECTORY_SEPARATOR))
{
$view_folder = APPPATH.strtr(
trim($view_folder, '/\\'),
'/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
);
}
else
{
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF;
exit(3); // EXIT_CONFIG
}
define('VIEWPATH', $view_folder.DIRECTORY_SEPARATOR);
/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
* --------------------------------------------------------------------
*
* And away we go...
*/
require_once BASEPATH.'core/CodeIgniter.php';
I'm not sure what to do, should I install something and change the config files?
What's up guys!
Watch for one of these situations:
Correctly edit the database connection information in the database.php file, located in "application / config / database.php
Define a base URL for your project at: application / config / config.php (line 27), so that it does not try to use its own computer as "localhost" instead of the remote computer. This configuration can be done in application / config / config.php. Search for $ config ["base_url"];
Tip: Sets the IP address of the machine where your application is hosted.
Give permissions to the application folder (or just the logs folder) so that the application can create / write to the files. An example would be to give 755 permission to it.
Maybe this will help.

Broken Images within phpwkhtmltopdf

Things to note, I have tested this on two different servers, Debian 9 and Ubuntu 14.04 and the same error persists. Right now I am using Ubuntu 14.04 with PHP 5, I have installed composer, I have installed both wkhtmltopdf and phpwkhtmltopdf correctly. How do I know this? Well wkhtmltopdf/image works via CLI, phpwkhtmltopdf also works via PHP however when I attempt to send the image to the client as an inline display or download the image corrupts. For example;
Visit desired url, for us its test.php
Phpwkhtmltopdf will send commands that hook up with the CLI version wkhtmltopdf
Once the page loads it will visit google.com, save a screenshot on the disk /var/www/html/tmp/page.jpg and that image opens/displays fine, however when I attempt to use $image->send('page.jpg'); the sent image is corrupt/wont open.
I have made two changes to the system, I have disabled mod_deflate within apache2 and I have also increased the max_filesize options within apache2's php.ini config file.
Dependencies
wkhtmltopdf - https://wkhtmltopdf.org/
phpwkhtmltopdf - https://github.com/mikehaertl/phpwkhtmltopdf
Live Example
http://155.254.35.63/test.php // Generate the image
http://155.254.35.63/tmp/page.png // The image file generated
test.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
<?php
$loader = require __DIR__ . '/vendor/autoload.php';
?>
<?php
use mikehaertl\wkhtmlto\Image;
$image = new \mikehaertl\wkhtmlto\Image('https://www.google.co.uk/search?q=what+is+the+time&oq=what+is+the+time&aqs=chrome.0.69i59j69i60l3j0l2.2977j0j4&sourceid=chrome&ie=UTF-8');
$image->setOptions(array(
'binary' => '/usr/local/bin/wkhtmltoimage',
'type' => 'png'
));
$image->saveAs('/var/www/html/tmp/page.png');
header('Content-Type: image/png');
echo file_get_contents('/var/www/html/tmp/page.jpg');
?>
File.php (Lines 72 to 83)
<?php
namespace mikehaertl\tmp;
/**
* File
*
* A convenience class for temporary files.
*
* #author Michael Härtl <haertl.mike#gmail.com>
* #version 1.1.0
* #license http://www.opensource.org/licenses/MIT
*/
class File
{
/**
* #var bool whether to delete the tmp file when it's no longer referenced or when the request ends.
* Default is `true`.
*/
public $delete = true;
/**
* #var string the name of this file
*/
protected $_fileName;
/**
* Constructor
*
* #param string $content the tmp file content
* #param string|null $suffix the optional suffix for the tmp file
* #param string|null $prefix the optional prefix for the tmp file. If null 'php_tmpfile_' is used.
* #param string|null $directory directory where the file should be created. Autodetected if not provided.
*/
public function __construct($content, $suffix = null, $prefix = null, $directory = null)
{
if ($directory===null) {
$directory = self::getTempDir();
}
if ($prefix===null) {
$prefix = 'php_tmpfile_';
}
$this->_fileName = tempnam($directory,$prefix);
if ($suffix!==null) {
$newName = $this->_fileName.$suffix;
rename($this->_fileName, $newName);
$this->_fileName = $newName;
}
file_put_contents($this->_fileName, $content);
}
/**
* Delete tmp file on shutdown if `$delete` is `true`
*/
public function __destruct()
{
if ($this->delete) {
unlink($this->_fileName);
}
}
/**
* Send tmp file to client, either inline or as download
*
* #param string|null $filename the filename to send. If empty, the file is streamed inline.
* #param string $contentType the Content-Type header
* #param bool $inline whether to force inline display of the file, even if filename is present.
*/
public function send($filename = null, $contentType, $inline = false)
{
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: image/png');
header('Content-Transfer-Encoding: binary');
if ($filename!==null || $inline) {
$disposition = $inline ? 'inline' : 'attachment';
header("Content-Disposition: $disposition; filename=\"$filename\"");
}
readfile($this->_fileName);
}
/**
* #param string $name the name to save the file as
* #return bool whether the file could be saved
*/
public function saveAs($name)
{
return copy($this->_fileName, $name);
}
/**
* #return string the full file name
*/
public function getFileName()
{
return $this->_fileName;
}
/**
* #return string the path to the temp directory
*/
public static function getTempDir()
{
if (function_exists('sys_get_temp_dir')) {
return sys_get_temp_dir();
} elseif ( ($tmp = getenv('TMP')) || ($tmp = getenv('TEMP')) || ($tmp = getenv('TMPDIR')) ) {
return realpath($tmp);
} else {
return '/tmp';
}
}
/**
* #return string the full file name
*/
public function __toString()
{
return $this->_fileName;
}
}
php.ini
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
;upload_tmp_dir = /var/www/html/tmp
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 50M
; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20
There are none (0) errors in the apache log file, which is really putting me off what the issue could be. I have attempted to find a resolution with the dev but no look;
https://github.com/mikehaertl/phpwkhtmltopdf/issues/278
Id appreciate the help on this one.
I have examined the page.jpg file your test site generates. The file itself is intact. This means there is nothing wrong with your plumbing.
The file header shows that instead of a standard JPEG file, yours is a JFIF variant. See if you can set the library to generate a PNG file to workaround this issue.
Edit: now that I see the generated file is correct, see if you can just stream the content instead of using $image->send. Send it youself:
header('Content-Type: image/png');
echo file_get_contents('/var/www/html/tmp/page.jpg');

Create release zip file on Github without tag name in it

I have this repo on Github - https://github.com/ronakg/awesome-flickr-gallery-plugin. It's a wordpress plugin for creating a photo gallery from your photos stored on Flickr.
Now what I want to achieve is - when I create a new release zip for my plugin, it should not use the tag name.
For example, I create releases 3.5.0 and 3.6.0. The folder structure for both the releases should be same.
awesome-flickr-gallery-plugin
/index.php
/README.txt
.
.
Right now it creates the release zipfiles like this:
awesome-flickr-gallery-plugin-3.5.0
/index.php
/README.txt
.
.
This is important for me as I want to serve this zip files directly as WordPress plugin updates for my users. This different file structure breaks the plugin update process in WordPress.
Any ideas?
I faced a similar problem with the prefix -master and solved with the following filter upgrader_source_selection. My repository is github-plugin-for-wordpress, adjust for your own.
/**
* Access this plugin’s working instance
*
* #wp-hook plugins_loaded
* #return object of this class
*/
public function plugin_setup()
{
add_filter( 'upgrader_source_selection', array( $this, 'rename_github_zip' ), 1, 3);
}
/**
* Removes the prefix "-master" when updating from GitHub zip files
*
* See: https://github.com/YahnisElsts/plugin-update-checker/issues/1
*
* #param string $source
* #param string $remote_source
* #param object $thiz
* #return string
*/
public function rename_github_zip( $source, $remote_source, $thiz )
{
if( strpos( $source, 'github-plugin-for-wordpress') === false )
return $source;
$path_parts = pathinfo( $source );
$newsource = trailingslashit( $path_parts['dirname'] ) . trailingslashit( 'github-plugin-for-wordpress' );
rename( $source, $newsource );
return $newsource;
}

Imagick with MAMP + php 5.3.6 + cakephp

I'm having an issue with imagick running on a MAMP installation within a cakephp app.
I have followed the install instructions as indicated here and the install seems to have worked in the sense that the class 'Imagick' exists for me if i test it in a php script (I can see the module is loaded in phpinfo). However any examples that I run utilising the class hang as soon as I echo any content. My view is:
<?php
/* Create a new imagick object */
$im = new Imagick();
/* Create new image. This will be used as fill pattern */
$im->newPseudoImage(50, 50, "gradient:red-black");
/* Create imagickdraw object */
$draw = new ImagickDraw();
/* Start a new pattern called "gradient" */
$draw->pushPattern('gradient', 0, 0, 50, 50);
/* Composite the gradient on the pattern */
$draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im);
/* Close the pattern */
$draw->popPattern();
/* Use the pattern called "gradient" as the fill */
$draw->setFillPatternURL('#gradient');
/* Set font size to 52 */
$draw->setFontSize(52);
/* Annotate some text */
$draw->annotation(20, 50, "Hello World!");
/* Create a new canvas object and a white image */
$canvas = new Imagick();
$canvas->newImage(350, 70, "white");
/* Draw the ImagickDraw on to the canvas */
$canvas->drawImage($draw);
/* 1px black border around the image */
$canvas->borderImage('black', 1, 1);
/* Set the format to PNG */
$canvas->setImageFormat('png');
/* Output the image */
header("Content-Type: image/png");
echo $canvas;
?>
This script will just hang as soon as the echo $canvas is encountered. The script works perfectly in a plain old php file i.e outside of cake but it hangs when visited via my cakephp app action. My action code is:
public function test(){
$this->layout = false;
}
Cake error log is empty.
Okay the issue was with how the header was set in cakephp. Cake didn't allow me to set the page header in the view that way.
I added the following code to the test action:
$this->response->type("image/png");
And it works perfectly now.

Create a QR-Code Image with the php imagick library

Hi,
We are using imagick for different image manipulations and have a request to add
QR watermarks in the end.
Right now I could only find PHP QR Code library which uses the GD2 library:
Implemented purely in PHP, no external dependencies except GD2
Is there any php snippet or library which uses imagick to create QR codes?
Looking at the PHP QR Code library, there is only one file (I think) that accesses the GD library: qrimage.php. So change that file to output via imagick and use the rest of PHP QR Code.
Below is a possible imagick output file I wrote to replace qrimage.php. However, I am unable to test this code, since I am on Windows, and cannot install imagick.
Can someone please debug it, and edit this post with any corrections?
<?php
/*
* PHP QR Code encoder
*
* Image output of code using GD2
*
* PHP QR Code is distributed under LGPL 3
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
define('QR_IMAGE', true);
class QRimage {
//----------------------------------------------------------------------
public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE)
{
$image = self::image($frame, $pixelPerPoint, $outerFrame, "png", 85, $filename, $saveandprint);
}
//----------------------------------------------------------------------
public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85)
{
$image = self::image($frame, $pixelPerPoint, $outerFrame, "jpeg", $q, $filename, $saveandprint);
}
//----------------------------------------------------------------------
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4,
$format = "png", $quality = 85, $filename = FALSE, $saveandprint = FALSE)
{
$imgH = count($frame);
$imgW = strlen($frame[0]);
$col[0] = new ImagickPixel("white");
$col[1] = new ImagickPixel("black");
$image = new Imagick();
$image->newImage($imgW, $imgH, $col[0]);
$image->setCompressionQuality($quality);
$image->setImageFormat($format);
$draw = new ImagickDraw();
$draw->setFillColor($col[1]);
for($y=0; $y<$imgH; $y++) {
for($x=0; $x<$imgW; $x++) {
if ($frame[$y][$x] == '1') {
$draw->point($x,$y);
}
}
}
$image->drawImage($draw);
$image->borderImage($col[0],$outerFrame,$outerFrame);
$image->scaleImage( $imgW * $pixelPerPoint, 0 );
if ($filename === FALSE) {
Header("Content-type: image/jpeg");
echo $image;
} else {
if($saveandprint===TRUE){
$image->writeImages($filename, true);
Header("Content-type: image/" . $format);
echo $image;
} else {
echo $image;
}
}
}
}
There is a merged file called phpqrcode.php that contains the entire qrimage.php, so you will either have to remerge that file, or else replace the relevant section.
If you use a different filename for the above code, you will have to change the reference in the file qrlib.php and merge.php.
I tested the above implementation and it worked.
There is one mistake : you missed to add the outerframe in the final image size.
$image->scaleImage( ($imgW + 2*$outerFrame) * $pixelPerPoint, 0 );
Also, it seems that GD library is a lot faster than ImageMagick in this case.
I benched the use of GD and imagick on the creation of the same 50 random qr codes.
I isolated the part were QR code are generated so in fact the use of QRimage::png.
I only teste png generation.
These are my results :
GD :
min time : 0,0148401260 s
max time : 0,0211210251 s
average : 0,0167747593 s
ImageMagick :
min time : 0,0799968243 s
max time : 0,1147611141 s
average : 0,0918840790 s
In the final code, this makes a little difference. The other part of the code takes something like 0.15s to run and on a large amount of codes it makes a difference (I benched QRcode::png with a result like : 0.17s per qrcode ith GD and 0.24s per code with imagemagick).

Categories