public function outputInForm() { $image = new CImage(); $image->name = $this->name; $image->src = $this->value; // return $image->generate(); }
/** * Validate and set static values * * @param array $init Configuration values. */ public function __construct($init) { // Validate arguments is_dir($init['imgDir']) or $this->errorMessage('The image dir is not a valid directory.'); is_writable($init['cacheDir']) or $this->errorMessage('The cache dir is not a writable directory.'); // Set static values self::$imgDir = $init['imgDir']; self::$cacheDir = $init['cacheDir']; self::$maxWidth = $init['maxWidth']; self::$maxHeight = $init['maxHeight']; }
/** * Test * * @return void */ public function testCreate2() { $img = new CImage(); $img->setSaveFolder(CACHE_PATH . "/dummy"); $img->setSource('dummy', CACHE_PATH . "/dummy"); $img->createDummyImage(200, 400); $img->generateFilename(null, false); $img->save(null, null, false); $filename = $img->getTarget(); $this->assertEquals(basename($filename), "dummy_200_400", "Filename not as expected on dummy image."); }
/** * Test * * @return void */ public function testCreate2() { $img = new CImage(); $img->setSaveFolder($this->cachepath); $img->setSource(self::DUMMY, $this->cachepath); $img->createDummyImage(200, 400); $img->generateFilename(null, false); $img->save(null, null, false); $filename = $img->getTarget(); $this->assertEquals(basename($filename), self::DUMMY . "_200_400", "Filename not as expected on dummy image."); }
<?php include 'CImage.php'; $file_name = "image/LENA.jpg"; //$file_name = "image/number2.jpg"; // Load $c_image = new CImage(); $c_image->setHeader($file_name); $params = array('type' => '', 'ext' => array()); // $params['ext']['red'] = 200; // $params['ext']['green'] = 100; // $params['ext']['blue'] = 100; //水平翻转 // $params['type'] = 'flipHorizontal'; //垂直翻转 // $params['type'] = 'flipVertical'; //对称翻转 // $params['type'] = 'flipSymmetric'; //灰色图片 // $params['type'] = 'greyScale'; //平移图片 // $params['type'] = 'moveImage'; // $params['ext']['offset_x'] = 20; // $params['ext']['offset_y'] = 100; // $params['ext']['red'] = 100; //旋转图片 //degree 0~90 // $params['type'] = 'retateImage'; // $params['ext']['degree'] = 90; //二值化 // $params['type'] = 'binaryzation';
/** * Test * * @return void * */ public function testRemoteHostWhitelistNotConfigured() { $img = new CImage(); $res = $img->isRemoteSourceOnWhitelist(null); $this->assertTrue($res, "Should allow when whitelist not configured."); }
/** * Saves the current image to a JPEG file with the given path. * @param string the path of the file to create. * @param int optional, the JPEG compression quality - an integer between 1 (poor quality, small file) and 100 (high quality, large file). If null (default), 'CImageJPEGQuality' will be used, if defined in Yii::app()->params. */ public function saveJPEG($path, $quality = null) { return parent::saveJPEG($path, $quality); $this->_path = $path; }
/** * Get the source files. */ $autoloader = getConfig('autoloader', false); $cimageClass = getConfig('cimage_class', false); if ($autoloader) { require $autoloader; } else { if ($cimageClass) { require $cimageClass; } } /** * Create the class for the image. */ $img = new CImage(); $img->setVerbose($verbose); /** * Allow or disallow remote download of images from other servers. * Passwords apply if used. * */ $allowRemote = getConfig('remote_allow', false); if ($allowRemote && $passwordMatch !== false) { $pattern = getConfig('remote_pattern', null); $img->setRemoteDownload($allowRemote, $pattern); $whitelist = getConfig('remote_whitelist', null); $img->setRemoteHostWhitelist($whitelist); } /** * shortcut, sc - extend arguments with a constant value, defined
if (isset($_REQUEST['sysmapid'])) { $options = array('sysmapids' => $_REQUEST['sysmapid'], 'editable' => 1, 'extendoutput' => 1); $maps = CMap::get($options); if (empty($maps)) { access_deny(); } else { $sysmap = reset($maps); } } // EXPORT /////////////////////////////////// if ($EXPORT_DATA) { $maps = get_request('maps', array()); $options = array('sysmapids' => $maps, 'select_selements' => API_OUTPUT_EXTEND, 'select_links' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND); $sysmaps = CMap::get($options); $options = array('sysmapids' => zbx_objectValues($sysmaps, 'sysmapid'), 'output' => API_OUTPUT_EXTEND, 'select_image' => 1); $images = CImage::get($options); prepareMapExport($sysmaps); $images = prepareImageExport($images); $sysmaps = array('images' => $images, 'sysmaps' => $sysmaps); $xml = zbxXML::arrayToXML($sysmaps); print $xml; exit; } // IMPORT /////////////////////////////////// $rules = get_request('rules', array()); if (!isset($_FILES['import_file'])) { foreach (array('maps', 'icons', 'background') as $key) { $rules[$key]['exist'] = 1; $rules[$key]['missed'] = 1; } }
<?php require 'CImage.php'; // Give original file to the class constructor $img = new CImage('original.jpg'); // Define thumbnail file $img->setThumbnail('/tmp/scaled.png'); // Define thumbnail format. If this is not given, then the // output file will be in JPEG-format. $img->setFormat('png'); // If there is already file what is set in setThumbnail, then // this will define that we must overwrite file. Otherwise // if file exists, it will throw Exception $img->setOverwrite(true); // And now, resize to 500x200, but keep aspect ratio. // If you want excatly 500x200, then use this without third parameter. $img->resize('500', '200', 'FIT');
<?php //include class-file require_once '../../src/image/CImage.php'; // Get incoming arguments $src = isset($_GET['src']) ? $_GET['src'] : null; $verbose = isset($_GET['verbose']) ? true : null; $quality = isset($_GET['quality']) ? $_GET['quality'] : 60; $ignoreCache = isset($_GET['no-cache']) ? true : false; //$saveAs = isset($_GET['save-as']) ? $_GET['save-as'] : null; - not needed acording to MOS... $newWidth = isset($_GET['width']) ? $_GET['width'] : null; $newHeight = isset($_GET['height']) ? $_GET['height'] : null; $cropToFit = isset($_GET['crop-to-fit']) ? true : null; $sharpen = isset($_GET['sharpen']) ? true : null; $blackwhite = isset($_GET['blackwhite']) ? true : null; $sepia = isset($_GET['sepia']) ? true : null; //require src attribute isset($src) or die('Must set src-attribute.'); //create instance of class and output image $imgFolder = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR; $cacheFolder = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR; $cimg = new CImage($imgFolder, $cacheFolder, $src, __FILE__, $quality, $newWidth, $newHeight, $cropToFit, $sharpen, $blackwhite, $sepia); $cimg->outputImage($ignoreCache, $verbose);
public function init() { parent::init(); self::$_matrix = array("й" => "i", "ц" => "c", "у" => "u", "к" => "k", "е" => "e", "н" => "n", "г" => "g", "ш" => "sh", "щ" => "shch", "з" => "z", "х" => "h", "ъ" => "", "ф" => "f", "ы" => "y", "в" => "v", "а" => "a", "п" => "p", "р" => "r", "о" => "o", "л" => "l", "д" => "d", "ж" => "zh", "э" => "e", "ё" => "e", "я" => "ya", "ч" => "ch", "с" => "s", "м" => "m", "и" => "i", "т" => "t", "ь" => "", "б" => "b", "ю" => "yu", "Й" => "I", "Ц" => "C", "У" => "U", "К" => "K", "Е" => "E", "Н" => "N", "Г" => "G", "Ш" => "SH", "Щ" => "SHCH", "З" => "Z", "Х" => "X", "Ъ" => "", "Ф" => "F", "Ы" => "Y", "В" => "V", "А" => "A", "П" => "P", "Р" => "R", "О" => "O", "Л" => "L", "Д" => "D", "Ж" => "ZH", "Э" => "E", "Ё" => "E", "Я" => "YA", "Ч" => "CH", "С" => "S", "М" => "M", "И" => "I", "Т" => "T", "Ь" => "", "Б" => "B", "Ю" => "YU", "«" => "", "»" => "", " " => "-", "\"" => "", "\\." => "", "–" => "-", "\\," => "", "\\(" => "", "\\)" => "", "\\?" => "", "\\!" => "", "\\:" => "", '#' => '', '№' => '', ' - ' => '-', '/' => '-', ' ' => '-'); }
function getImageByIdent($ident) { zbx_value2array($ident); if (!isset($ident['name'])) { return 0; } static $images; if (is_null($images)) { // get All images $images = array(); $options = array('output' => API_OUTPUT_EXTEND, 'nodeids' => get_current_nodeid(true)); $dbImages = CImage::get($options); foreach ($dbImages as $inum => $img) { if (!isset($images[$img['name']])) { $images[$img['name']] = array(); } $nodeName = get_node_name_by_elid($img['imageid'], true); if (!is_null($nodeName)) { $images[$img['name']][$nodeName] = $img; } else { $images[$img['name']][] = $img; } } //------ } $ident['name'] = trim($ident['name'], ' '); if (!isset($images[$ident['name']])) { return 0; } $sImages = $images[$ident['name']]; if (!isset($ident['node'])) { return reset($sImages); } else { if (isset($sImages[$ident['node']])) { return $sImages[$ident['node']]; } else { return 0; } } }
public static function parseMap($rules) { global $USER_DETAILS; $importMaps = self::XMLtoArray(self::$xml); if (!isset($importMaps['zabbix_export'])) { $importMaps['zabbix_export'] = $importMaps; } try { if ($USER_DETAILS['type'] == USER_TYPE_SUPER_ADMIN) { $images = $importMaps['zabbix_export']['images']; $images_to_add = array(); $images_to_update = array(); foreach ($images as $inum => $image) { if (CImage::exists($image)) { if ($image['imagetype'] == IMAGE_TYPE_ICON && isset($rules['icons']['exist']) || $image['imagetype'] == IMAGE_TYPE_BACKGROUND && isset($rules['background']['exist'])) { $options = array('filter' => array('name' => $image['name']), 'output' => API_OUTPUT_SHORTEN); $imgs = CImage::get($options); $img = reset($imgs); $image['imageid'] = $img['imageid']; // image will be decoded in class.image.php $image['image'] = $image['encodedImage']; unset($image['encodedImage']); $images_to_update[] = $image; } } else { if ($image['imagetype'] == IMAGE_TYPE_ICON && isset($rules['icons']['missed']) || $image['imagetype'] == IMAGE_TYPE_BACKGROUND && isset($rules['background']['missed'])) { // No need to decode_base64 $image['image'] = $image['encodedImage']; unset($image['encodedImage']); $images_to_add[] = $image; } } } //sdi($images_to_add); if (!empty($images_to_add)) { $result = CImage::create($images_to_add); if (!$result) { throw new Exception(S_CANNOT_ADD_IMAGE); } } //sdi($images_to_update); if (!empty($images_to_update)) { $result = CImage::update($images_to_update); if (!$result) { throw new Exception(S_CANNOT_UPDATE_IMAGE); } } } $importMaps = $importMaps['zabbix_export']['sysmaps']; $sysmaps = array(); foreach ($importMaps as $mnum => &$sysmap) { unset($sysmap['sysmapid']); $exists = CMap::exists(array('name' => $sysmap['name'])); if ($exists && isset($rules['maps']['exist'])) { $db_maps = CMap::getObjects(array('name' => $sysmap['name'])); if (empty($db_maps)) { throw new Exception(S_NO_PERMISSIONS_FOR_MAP . ' [' . $sysmap['name'] . '] import'); } $db_map = reset($db_maps); $sysmap['sysmapid'] = $db_map['sysmapid']; } else { if ($exists || !isset($rules['maps']['missed'])) { info('Map [' . $sysmap['name'] . '] skipped - user rule'); unset($importMaps[$mnum]); continue; // break if not update exist } } if (isset($sysmap['backgroundid'])) { $image = getImageByIdent($sysmap['backgroundid']); if (!$image) { error(S_CANNOT_FIND_BACKGROUND_IMAGE . ' "' . $sysmap['backgroundid']['name'] . '" ' . S_USED_IN_EXPORTED_MAP_SMALL . ' "' . $sysmap['name'] . '"'); $sysmap['backgroundid'] = 0; } else { $sysmap['backgroundid'] = $image['imageid']; } } else { $sysmap['backgroundid'] = 0; } if (!isset($sysmap['selements'])) { $sysmap['selements'] = array(); } if (!isset($sysmap['links'])) { $sysmap['links'] = array(); } foreach ($sysmap['selements'] as $snum => &$selement) { $nodeCaption = isset($selement['elementid']['node']) ? $selement['elementid']['node'] . ':' : ''; if (!isset($selement['elementid'])) { $selement['elementid'] = 0; } switch ($selement['elementtype']) { case SYSMAP_ELEMENT_TYPE_MAP: $db_sysmaps = CMap::getObjects($selement['elementid']); if (empty($db_sysmaps)) { $error = S_CANNOT_FIND_MAP . ' "' . $nodeCaption . $selement['elementid']['name'] . '" ' . S_USED_IN_EXPORTED_MAP_SMALL . ' "' . $sysmap['name'] . '"'; throw new Exception($error); } $tmp = reset($db_sysmaps); $selement['elementid'] = $tmp['sysmapid']; break; case SYSMAP_ELEMENT_TYPE_HOST_GROUP: $db_hostgroups = CHostgroup::getObjects($selement['elementid']); if (empty($db_hostgroups)) { $error = S_CANNOT_FIND_HOSTGROUP . ' "' . $nodeCaption . $selement['elementid']['name'] . '" ' . S_USED_IN_EXPORTED_MAP_SMALL . ' "' . $sysmap['name'] . '"'; throw new Exception($error); } $tmp = reset($db_hostgroups); $selement['elementid'] = $tmp['groupid']; break; case SYSMAP_ELEMENT_TYPE_HOST: $db_hosts = CHost::getObjects($selement['elementid']); if (empty($db_hosts)) { $error = S_CANNOT_FIND_HOST . ' "' . $nodeCaption . $selement['elementid']['host'] . '" ' . S_USED_IN_EXPORTED_MAP_SMALL . ' "' . $sysmap['name'] . '"'; throw new Exception($error); } $tmp = reset($db_hosts); $selement['elementid'] = $tmp['hostid']; break; case SYSMAP_ELEMENT_TYPE_TRIGGER: $db_triggers = CTrigger::getObjects($selement['elementid']); if (empty($db_triggers)) { $error = S_CANNOT_FIND_TRIGGER . ' "' . $nodeCaption . $selement['elementid']['host'] . ':' . $selement['elementid']['description'] . '" ' . S_USED_IN_EXPORTED_MAP_SMALL . ' "' . $sysmap['name'] . '"'; throw new Exception($error); } $tmp = reset($db_triggers); $selement['elementid'] = $tmp['triggerid']; break; case SYSMAP_ELEMENT_TYPE_IMAGE: default: break; } $icons = array('iconid_off', 'iconid_on', 'iconid_unknown', 'iconid_disabled', 'iconid_maintenance'); foreach ($icons as $icon) { if (isset($selement[$icon])) { $image = getImageByIdent($selement[$icon]); if (!$image) { $error = S_CANNOT_FIND_IMAGE . ' "' . $selement[$icon]['name'] . '" ' . S_USED_IN_EXPORTED_MAP_SMALL . ' "' . $sysmap['name'] . '"'; throw new Exception($error); } $selement[$icon] = $image['imageid']; } else { $selement[$icon] = 0; } } } unset($selement); foreach ($sysmap['links'] as $lnum => &$link) { if (!isset($link['linktriggers'])) { continue; } foreach ($link['linktriggers'] as $ltnum => &$linktrigger) { $nodeCaption = isset($linktrigger['triggerid']['node']) ? $linktrigger['triggerid']['node'] . ':' : ''; $db_triggers = CTrigger::getObjects($linktrigger['triggerid']); if (empty($db_triggers)) { $error = S_CANNOT_FIND_TRIGGER . ' "' . $nodeCaption . $linktrigger['triggerid']['host'] . ':' . $linktrigger['triggerid']['description'] . '" ' . S_USED_IN_EXPORTED_MAP_SMALL . ' "' . $sysmap['name'] . '"'; throw new Exception($error); } $tmp = reset($db_triggers); $linktrigger['triggerid'] = $tmp['triggerid']; } unset($linktrigger); } unset($link); $sysmaps[] = $sysmap; } unset($sysmap); $importMaps = $sysmaps; foreach ($importMaps as $mnum => $importMap) { $sysmap = $importMap; if (isset($importMap['sysmapid'])) { $result = CMap::update($importMap); $sysmapids = $result['sysmapids']; // Deleteing all selements (with links) $db_selementids = array(); $res = DBselect('SELECT selementid FROM sysmaps_elements WHERE sysmapid=' . $sysmap['sysmapid']); while ($db_selement = DBfetch($res)) { $db_selementids[$db_selement['selementid']] = $db_selement['selementid']; } delete_sysmaps_element($db_selementids); //---- } else { // first we must create an empty map without any elements (they will be added below) $mapToCreate = $importMap; $mapToCreate['selements'] = array(); $mapToCreate['links'] = array(); $result = CMap::create($mapToCreate); $sysmapids = $result['sysmapids']; $sysmap['sysmapid'] = reset($sysmapids); } // adding elements and links $selements = $importMap['selements']; $links = $importMap['links']; foreach ($selements as $id => $selement) { if (!isset($selement['elementid']) || $selement['elementid'] == 0) { $selement['elementid'] = 0; $selement['elementtype'] = SYSMAP_ELEMENT_TYPE_IMAGE; } if (!isset($selement['iconid_off']) || $selement['iconid_off'] == 0) { throw new Exception(S_NO_ICON_FOR_MAP_ELEMENT . ' ' . $sysmap['name'] . ':' . $selement['label']); } $selement['sysmapid'] = $sysmap['sysmapid']; $selementids = CMap::addElements($selement); $selementid = reset($selementids); foreach ($links as $id => &$link) { if ($link['selementid1'] == $selement['selementid']) { $links[$id]['selementid1'] = $selementid; } else { if ($link['selementid2'] == $selement['selementid']) { $links[$id]['selementid2'] = $selementid; } } } unset($link); } foreach ($links as $id => $link) { if (!isset($link['linktriggers'])) { $link['linktriggers'] = array(); } $link['sysmapid'] = $sysmap['sysmapid']; $result = CMap::addLinks($link); } if (isset($importMap['sysmapid'])) { info(S_MAP . ' [' . $sysmap['name'] . '] ' . S_UPDATED_SMALL); } else { info(S_MAP . ' [' . $sysmap['name'] . '] ' . S_ADDED_SMALL); } } return true; } catch (Exception $e) { error($e->getMessage()); return false; } }
<?php /** * RUWT page controller */ include __DIR__ . '/config.php'; $settings = array('imageDir' => __DIR__ . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR, 'cacheDir' => __DIR__ . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR, 'maxWidth' => 2000, 'maxHeight' => 2000); $img = new CImage($settings); $img->Show();
<?php /** * This is a PHP skript to process images using PHP GD. * */ // Include the CImage class include __DIR__ . '/../src/CImage/CImage.php'; // // Ensure error reporting is on // error_reporting(-1); // Report all type of errors ini_set('display_errors', 1); // Display all errors ini_set('output_buffering', 0); // Do not buffer outputs, write directly // // Define some constant values, append slash // Use DIRECTORY_SEPARATOR to make it work on both windows and unix. // define('IMG_PATH', __DIR__ . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR); define('CACHE_PATH', __DIR__ . '/cache/'); $maxWidth = $maxHeight = 2000; $imgFunc = new CImage($maxWidth, $maxHeight); $imgFunc->displayImage();
/** * Test * * @return void */ public function testCreate2() { $img = new CImage(); $filename = $img->convert2sRGBColorSpace('car.jpg', IMAGE_PATH, $this->cache, $this->srgbColorProfile); $this->assertFalse($filename); }
private static function image($action, $params) { CImage::$error = array(); switch ($action) { default: $result = call_user_func(array('CImage', $action), $params); } self::$result = $result; }
$verify_code = trim($_SESSION['verify_code']); $len = strlen($verify_code); //---- $x = 3; $y = 3; $w = imagefontwidth(5); mt_srand($this->MakeSeed()); //---- for ($i = 0; $i < $len; ++$i) { imagestring($im, 5, $x, $y + mt_rand(0, 4) - 2, $verify_code[$i], $black); //---- $x += $w; } //---- output the image imagegif($im); //---- exit; } function Show() { } function MakeSeed() { list($usec, $sec) = explode(' ', microtime()); return (double) $sec + (double) $usec * 100000; } } //--- show captcha $image = new CImage(); $image->Show(); //+------------------------------------------------------------------+
} } else { errorPage("Hotlinking/leeching not allowed.", 403); } } verbose("allow_hotlinking = {$allowHotlinking}"); verbose("referer = {$referer}"); verbose("referer host = {$refererHost}"); $autoloader = getConfig('autoloader', false); $cimageClass = getConfig('cimage_class', false); if ($autoloader) { require $autoloader; } elseif ($cimageClass) { require $cimageClass; } $img = new CImage(); $img->setVerbose($verbose || $verboseFile); $allowRemote = getConfig('remote_allow', false); if ($allowRemote && $passwordMatch !== false) { $pattern = getConfig('remote_pattern', null); $img->setRemoteDownload($allowRemote, $pattern); $whitelist = getConfig('remote_whitelist', null); $img->setRemoteHostWhitelist($whitelist); } $shortcut = get(array('shortcut', 'sc'), null); $shortcutConfig = getConfig('shortcut', array('sepia' => "&f=grayscale&f0=brightness,-10&f1=contrast,-20&f2=colorize,120,60,0,0&sharpen")); verbose("shortcut = {$shortcut}"); if (isset($shortcut) && isset($shortcutConfig[$shortcut])) { parse_str($shortcutConfig[$shortcut], $get); verbose("shortcut-constant = {$shortcutConfig[$shortcut]}"); $_GET = array_merge($_GET, $get);
<?php /** * This is a PHP script which call CImage to get an image. * */ // Array for configuration $config = array('imgDir' => realpath(__DIR__) . DIRECTORY_SEPARATOR, 'cacheDir' => realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'cache') . DIRECTORY_SEPARATOR, 'maxWidth' => 2000, 'maxHeight' => 2000); // Include source from CImage.php. require_once '../../src/CImage/CImage.php'; // Create a image object $image = new CImage($config); // Get the incoming arguments and set the values in the image object $image->setSrc(isset($_GET['src']) ? $_GET['src'] : null); $image->setVerbose(isset($_GET['verbose']) ? true : null); $image->setSaveAs(isset($_GET['save-as']) ? $_GET['save-as'] : null); $image->setQuality(isset($_GET['quality']) ? $_GET['quality'] : 60); $image->setIgnoreCache(isset($_GET['no-cache']) ? true : null); $image->setNewWidth(isset($_GET['width']) ? $_GET['width'] : null); $image->setNewHeight(isset($_GET['height']) ? $_GET['height'] : null); $image->setCropToFit(isset($_GET['crop-to-fit']) ? true : null); $image->setSharpen(isset($_GET['sharpen']) ? true : null); // Get the image $image->getOutput();