<?php /** * Tutoriel file * Description : Adding a single image to the document * You need PHP 5.2 at least * You need Zip Extension or PclZip library * * @copyright GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com) * @license http://www.gnu.org/copyleft/gpl.html GPL License * @version 1.3 */ // Make sure you have Zip extension or PclZip library loaded // First : include the librairy require_once '../library/Odf.php'; $odf = new Odf("tutoriel2.odt"); $odf->setVars('titre', 'Anaska formation'); $message = "Anaska, leader Fran�ais de la formation informatique sur les technologies \nOpen Source, propose un catalogue de plus de 50 formations dont certaines pr�parent \naux certifications Linux, MySQL, PHP et PostgreSQL."; $odf->setVars('message', $message); $odf->setImage('image', './images/anaska.jpg'); // We export the file $odf->exportAsAttachedFile();
/** * Generate barcode image * @param object $barcode Instance of wps_barcodegen * @param string $meta Numerical code of barcode * @param string $type Texte for complete message * @param string $price Price of product * @param string $title Title of product */ public function generate_image(&$barcode, $meta, $type, $price, $title, $post_ID = 0) { if (!empty($meta)) { $barcode->setGenerateCode($meta); $binCode = $barcode->getBinCode(); $px = 3.779528; $x = round(66 * $px); //249.449 px $y = round(50 * $px); //188.976 px $bar_size = round(63.393 / 72); //0.880 px $len = 0; $test = ''; while ($len !== strlen($binCode)) { $test .= substr($binCode, $len, 7) . ' '; $len = $len + 7; } $im = imagecreate($x, $y); $background_color = imagecolorallocate($im, 255, 255, 255); $start = round(5.79 * $px); //21.883 /*Write First left guard*/ $this->imgNormalGuard($im, $start, $start + $bar_size, imagecolorallocate($im, 0, 0, 0)); $this->imgNormalGuard($im, $start + $bar_size * 2, $start + $bar_size * 3, imagecolorallocate($im, 255, 255, 255)); $this->imgNormalGuard($im, $start + $bar_size * 4, $start + $bar_size * 5, imagecolorallocate($im, 0, 0, 0)); $pos = $start + $bar_size * 7; $newPos = $pos + $bar_size; /*Write left barcode*/ for ($i = 0; $i < 42; $i++) { if (substr($binCode, $i, 1) === '0') { $color = imagecolorallocate($im, 255, 255, 255); } else { $color = imagecolorallocate($im, 0, 0, 0); } $this->imgSymbole($im, $pos, $newPos, $color); $newPos = $pos + $bar_size; $pos = $newPos + $bar_size; } /*Writer center guard*/ $pos = $newPos; $this->imgNormalGuard($im, $pos, $newPos + $bar_size, imagecolorallocate($im, 255, 255, 255)); $this->imgNormalGuard($im, $pos + $bar_size * 2, $newPos + $bar_size * 3, imagecolorallocate($im, 0, 0, 0)); $this->imgNormalGuard($im, $pos + $bar_size * 4, $newPos + $bar_size * 5, imagecolorallocate($im, 255, 255, 255)); $this->imgNormalGuard($im, $pos + $bar_size * 6, $newPos + $bar_size * 7, imagecolorallocate($im, 0, 0, 0)); $this->imgNormalGuard($im, $pos + $bar_size * 8, $newPos + $bar_size * 9, imagecolorallocate($im, 255, 255, 255)); $pos = $newPos + $bar_size * 10; /*Write right barcode*/ for ($i = 42; $i < 84; $i++) { if (substr($binCode, $i, 1) === '0') { $color = imagecolorallocate($im, 255, 255, 255); } else { $color = imagecolorallocate($im, 0, 0, 0); } $newPos = $pos + $bar_size; $this->imgSymbole($im, $pos, $newPos, $color); $pos = $newPos + $bar_size; } /*Write right guard*/ $pos = $newPos + $bar_size; $this->imgNormalGuard($im, $pos, $pos + $bar_size, imagecolorallocate($im, 0, 0, 0)); $this->imgNormalGuard($im, $pos + $bar_size * 2, $pos + $bar_size * 3, imagecolorallocate($im, 255, 255, 255)); $this->imgNormalGuard($im, $pos + $bar_size * 4, $pos + $bar_size * 5, imagecolorallocate($im, 0, 0, 0)); $textSize = 16; $font = WPS_BARCODE_PATH . '/arialbd.ttf'; imagettftext($im, $textSize, 0, 8, $y - $start - 5, imagecolorallocate($im, 0, 0, 0), $font, substr($meta, 0, 1)); $continue = true; $i = 28; $j = 0; /*Write left number code*/ while ($j < 5) { $j = $j + 1; imagettftext($im, $textSize, 0, $i, $y - $start - 5, imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j, 1)); $i = $i + 14; } /*Write right number code*/ while ($j < 11) { $j = $j + 1; imagettftext($im, $textSize, 0, $i + 6, $y - $start - 5, imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j, 1)); $i = $i + 15; } imagettftext($im, $textSize, 0, $i + 4, $y - $start - 5, imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j + 1, 1)); /*Write ref product and price*/ $textSize = 12; $currency = wpshop_tools::wpshop_get_currency() === '€' ? "€" : wpshop_tools::wpshop_get_currency(); if ($type === __('coupon', 'wps_barcode')) { $coupon_postmeta = get_post_meta($post_ID, 'wpshop_coupon_discount_type'); if ($coupon_postmeta[0] === 'percent') { $price = $price . ' %'; } else { $price = sprintf(number_format($price, 2) . ' ' . $currency); } } else { $price = sprintf(number_format($price, 2) . ' ' . $currency); } imagettftext($im, $textSize, 0, 20, round(6 * $px), imagecolorallocate($im, 0, 0, 0), $font, $title); imagettftext($im, $textSize, 0, $x / 2 + 40, round(6 * $px), imagecolorallocate($im, 0, 0, 0), $font, $price); ob_start(); imagepng($im); $img = ob_get_clean(); echo '<p><img src="data:image/png;base64,' . base64_encode($img) . '" id="barcode" width="160" height="90" /></p>'; echo '<p style="text-align: right"><button class="button ' . 'button-primary button-large" type="button"' . 'id="print_barcode">' . __('Print', 'wps_barcode') . '</button></p>'; wp_mkdir_p(WPS_BARCODE_UPLOAD); file_put_contents(WPS_BARCODE_UPLOAD . $meta . '.png', $img); /*Generate ODT File*/ try { if (!class_exists('Odf')) { require_once WPS_BARCODE_PATH . '/librairies/odtphp/odf.php'; } $odf = new Odf(WPS_BARCODE_PATH . 'assets/medias/avery_a4_991_677.ott'); $odf->setImage('barcode', WPS_BARCODE_UPLOAD . $meta . '.png'); $odf->saveToDisk(WPS_BARCODE_UPLOAD . $meta . '.odt'); } catch (Exception $e) { echo __('Generation problem', 'wps_barcode'); } } else { echo '<p>' . sprintf(__('None bardcode generated as you did create %s.', 'wps_barcode'), $type) . '</p>'; } }