/** * The constructor generates a Captcha image. * * @param int $dotNoise The dot noise level. Default: 100. * @param int $lineNoise The line noise level. Default: 5. * @param int $wordLen The length of the Captcha word. Default: 6. * @param int $timeout The timeout in seconds. Default: 1800. * @return OSS_Captcha_Image */ public function __construct($dotNoise = 100, $lineNoise = 5, $wordLen = 6, $timeout = 1800) { parent::__construct(); $captchaDir = OSS_Utils::getTempDir() . '/captchas'; if (!file_exists($captchaDir)) { mkdir($captchaDir, 0777, true); } if (strpos(dirname(__FILE__), 'src/') === false) { $font = dirname(__FILE__) . '/../../data/font/freeserif.ttf'; } else { $font = dirname(__FILE__) . '/../../../data/font/freeserif.ttf'; } $this->setTimeout($timeout)->setWordLen($wordLen)->setHeight(80)->setFont($font)->setFontSize(40)->setImgDir($captchaDir)->setDotNoiseLevel($dotNoise)->setLineNoiseLevel($lineNoise); return $this; }
/** * Converts a HTML file to PDF using htmldoc. Please note that the current stable version of htmldoc (v1.8.27) does not support CSS. Make sure PHP has write permission in the * output directory. Also don't forget that relative paths are relative to the currently executing PHP script (include() and require() doesn't count in that). * Using command line OpenOffice might be a better solution (a necessary macro and a tiny, one line shell script are available on the internet), as it supports everything in the HTML, * CSS, images, etc, while the htmldoc 1.9.x is still in "developer snapshot" state. * * @param string $html the input HTML file name * @param string $pdf the output PDF file name * @param bool $embedFonts default false embed the used fonts to the genereated PDF or not - can save 100's of kBytes even in a plain PDF (think of email sending) * @return bool */ public static function HtmlToPdf($html, $pdf, $embedFonts = false) { $tempFile = OSS_Utils::getTempDir() . '/html_to_pdf_' . md5(mt_rand()) . '.html'; $res = file_put_contents($tempFile, mb_convert_encoding(file_get_contents($html), 'HTML-ENTITIES')); if (!$res) { return false; } // a ' &> /dev/null' at the end of the command should work, but it doesn't $command = 'htmldoc --webpage --continuous --compression=9' . ($embedFonts == false ? ' --no-embedfonts' : '') . ' --fontsize 10 --size A4 --top 2cm --bottom 2cm --left 2cm --right 2cm -t pdf14 -f ' . escapeshellarg($pdf) . ' ' . escapeshellarg($tempFile); //print "\n\n" . $vCommand . "\n\n"; die(); //file_put_contents('../var/tmp/command.txt', $vCommand); $res = @exec($command); if (!$res) { return false; } return @file_exists($pdf); }
/** * Takes an id as a parameter, and prints the matching CAPTCHA image as a binary raw string to the output, * or prints nothing if no matching CAPTCHA found. */ public function captchaImageAction() { $captchaId = preg_replace("/[^0-9a-z]+/u", '', strtolower(basename($this->_getParam('id')))); $captchaFile = OSS_Utils::getTempDir() . "/captchas/{$captchaId}.png"; if (@file_exists($captchaFile)) { Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); @ob_end_clean(); header('Content-type: image/png'); @readfile($captchaFile); } else { $this->_forward('error-404', 'error'); } }