本文整理匯總了PHP中ImageManager::createWhiteImage方法的典型用法代碼示例。如果您正苦於以下問題:PHP ImageManager::createWhiteImage方法的具體用法?PHP ImageManager::createWhiteImage怎麽用?PHP ImageManager::createWhiteImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ImageManager
的用法示例。
在下文中一共展示了ImageManager::createWhiteImage方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: generate
/**
* 生成驗證碼字符串,寫入SESSION,將字符串圖片返回給瀏覽器
*
* @param $len
* @param int $width
* @param int $height
* @param int $font_size
*/
public static function generate($len, $width = 108, $height = 30, $font_size = 18)
{
$sizes = array('18' => array('width' => 25, 'height' => 25));
$words = self::words($len);
session_start();
$session_key = 'captcha';
$_SESSION[$session_key] = strtolower($words);
$image = ImageManager::createWhiteImage($width, $height);
$font_config = array('spacing' => -17, 'font' => '5.ttf');
$font_path = dirname(__FILE__) . '/font/' . $font_config['font'];
$color = imagecolorallocate($image, mt_rand(0, 100), mt_rand(20, 120), mt_rand(50, 150));
$rand = 0;
$w = $sizes[$font_size]['width'] * $len;
$h = $sizes[$font_size]['height'];
$x = round(($width - $w) / 2);
$y = round(($height + $h) / 2) - 6;
$coors = imagettftext($image, $font_size, $rand, $x, $y, $color, $font_path, $words);
if ($coors) {
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Pragma: no-cache");
header("Cache-control: private");
header('Content-Type: image/png');
ob_clean();
imagepng($image);
imagedestroy($image);
}
exit;
}
示例2: createDestImage
/**
* @deprecated 1.5.0
*/
function createDestImage($width, $height)
{
Tools::displayAsDeprecated();
return ImageManager::createWhiteImage($width, $height);
}
示例3: cut
/**
* Cut image
*
* @param array $src_file Origin filename
* @param string $dst_file Destination filename
* @param integer $dst_width Desired width
* @param integer $dst_height Desired height
* @param string $file_type
* @param int $dst_x
* @param int $dst_y
*
* @return bool Operation result
*/
public static function cut($src_file, $dst_file, $dst_width = null, $dst_height = null, $file_type = 'jpg', $dst_x = 0, $dst_y = 0)
{
if (!file_exists($src_file)) {
return false;
}
// Source information
$src_info = getimagesize($src_file);
$src = array('width' => $src_info[0], 'height' => $src_info[1], 'ressource' => ImageManager::create($src_info[2], $src_file));
// Destination information
$dest = array();
$dest['x'] = $dst_x;
$dest['y'] = $dst_y;
$dest['width'] = !is_null($dst_width) ? $dst_width : $src['width'];
$dest['height'] = !is_null($dst_height) ? $dst_height : $src['height'];
$dest['ressource'] = ImageManager::createWhiteImage($dest['width'], $dest['height']);
$white = imagecolorallocate($dest['ressource'], 255, 255, 255);
imagecopyresampled($dest['ressource'], $src['ressource'], 0, 0, $dest['x'], $dest['y'], $dest['width'], $dest['height'], $dest['width'], $dest['height']);
imagecolortransparent($dest['ressource'], $white);
$return = ImageManager::write($file_type, $dest['ressource'], $dst_file);
return $return;
}