本文整理汇总了PHP中imagecreatefromxbm函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecreatefromxbm函数的具体用法?PHP imagecreatefromxbm怎么用?PHP imagecreatefromxbm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecreatefromxbm函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: _load_image
private function _load_image($path)
{
list($w, $h, $type) = getimagesize($path);
switch ($type) {
case IMAGETYPE_GIF:
$this->_format = 'gif';
return imagecreatefromgif($path);
case IMAGETYPE_JPEG:
$this->_format = 'jpg';
return imagecreatefromjpeg($path);
case IMAGETYPE_PNG:
$this->_format = 'png';
return imagecreatefrompng($path);
case IMAGETYPE_SWF:
$this->_format = 'swf';
return imagecreatefromswf($path);
case IMAGETYPE_WBMP:
$this->_format = 'wbmp';
return imagecreatefromwbmp($path);
case IMAGETYPE_XBM:
$this->_format = 'xbm';
return imagecreatefromxbm($path);
default:
return imagecreatefromstring(file_get_contents($path));
}
return false;
}
开发者ID:ideatic,项目名称:tinyfier,代码行数:27,代码来源:Tool.php
示例2: build_image
/** Returns an array. Element 0 - GD resource. Element 1 - width. Element 2 - height.
* Returns FALSE on failure. The only one parameter $image can be an instance of this class,
* a GD resource, an array(width, height) or path to image file.
* @param mixed $image
* @return array */
protected function build_image($image)
{
if ($image instanceof gd) {
$width = $image->get_width();
$height = $image->get_height();
$image = $image->get_image();
} elseif (is_resource($image) && get_resource_type($image) == "gd") {
$width = @imagesx($image);
$height = @imagesy($image);
} elseif (is_array($image)) {
list($key, $width) = each($image);
list($key, $height) = each($image);
$image = imagecreatetruecolor($width, $height);
} elseif (false !== (list($width, $height, $type) = @getimagesize($image))) {
$image = $type == IMAGETYPE_GIF ? @imagecreatefromgif($image) : ($type == IMAGETYPE_WBMP ? @imagecreatefromwbmp($image) : ($type == IMAGETYPE_JPEG ? @imagecreatefromjpeg($image) : ($type == IMAGETYPE_JPEG2000 ? @imagecreatefromjpeg($image) : ($type == IMAGETYPE_PNG ? imagecreatefrompng($image) : ($type == IMAGETYPE_XBM ? @imagecreatefromxbm($image) : false)))));
if ($type == IMAGETYPE_PNG) {
imagealphablending($image, false);
}
}
$return = is_resource($image) && get_resource_type($image) == "gd" && isset($width) && isset($height) && preg_match('/^[1-9][0-9]*$/', $width) !== false && preg_match('/^[1-9][0-9]*$/', $height) !== false ? array($image, $width, $height) : false;
if ($return !== false && isset($type)) {
$this->type = $type;
}
return $return;
}
开发者ID:Evrika,项目名称:Vidal,代码行数:30,代码来源:class_gd.php
示例3: input
public function input($input)
{
// if is not a string, not an existing file or not a file ressource
if (!is_string($input) || !file_exists($input) || !is_file($input)) {
throw new \InvalidArgumentException('Input file is not a valid ressource.');
}
$this->inputPath = $input;
list($this->inputWidth, $this->inputHeight, $this->inputType) = getimagesize($input);
switch ($this->inputType) {
case IMAGETYPE_GIF:
if (!function_exists('imagecreatefromgif')) {
throw new CapabilityException('GIF is not supported.');
}
$this->input = imagecreatefromgif($input);
break;
case IMAGETYPE_JPEG:
if (!function_exists('imagecreatefromjpeg')) {
throw new CapabilityException('JPEG is not supported.');
}
$this->input = imagecreatefromjpeg($input);
break;
case IMAGETYPE_PNG:
if (!function_exists('imagecreatefrompng')) {
throw new CapabilityException('PNG is not supported.');
}
$this->input = imagecreatefrompng($input);
break;
case IMAGETYPE_WBMP:
if (!function_exists('imagecreatefromwbmp')) {
throw new CapabilityException('WBMP is not supported.');
}
$this->input = imagecreatefromwbmp($input);
break;
// Not supported yet in PHP 5.5. WebP is supported since in PHP 5.5 (https://bugs.php.net/bug.php?id=65038)
// Not supported yet in PHP 5.5. WebP is supported since in PHP 5.5 (https://bugs.php.net/bug.php?id=65038)
case defined('IMAGETYPE_WEBP') && IMAGETYPE_WEBP:
if (!function_exists('imagecreatefromwebp')) {
throw new CapabilityException('WebP is not supported.');
}
$this->input = imagecreatefromwebp($input);
break;
case IMAGETYPE_XBM:
if (!function_exists('imagecreatefromxbm')) {
throw new CapabilityException('XBM is not supported.');
}
$this->input = imagecreatefromxbm($input);
break;
case defined('IMAGETYPE_WEBP') && IMAGETYPE_XPM:
if (!function_exists('imagecreatefromxpm')) {
throw new CapabilityException('XPM is not supported.');
}
$this->input = imagecreatefromxpm($input);
break;
default:
throw new CapabilityException('Unsupported input file type.');
break;
}
$this->applyExifTransformations($this->input);
}
开发者ID:moust,项目名称:paint,代码行数:59,代码来源:Paint.php
示例4: open_image
function open_image($file)
{
list($width, $height, $type, $attr) = getimagesize($file);
//echo "Type: ".$type."<br />";
// http://www.php.net/manual/en/function.exif-imagetype.php
/*1 IMAGETYPE_GIF
2 IMAGETYPE_JPEG
3 IMAGETYPE_PNG
4 IMAGETYPE_SWF
5 IMAGETYPE_PSD
6 IMAGETYPE_BMP
7 IMAGETYPE_TIFF_II (intel byte order)
8 IMAGETYPE_TIFF_MM (motorola byte order)
9 IMAGETYPE_JPC
10 IMAGETYPE_JP2
11 IMAGETYPE_JPX
12 IMAGETYPE_JB2
13 IMAGETYPE_SWC
14 IMAGETYPE_IFF
15 IMAGETYPE_WBMP
16 IMAGETYPE_XBM
17 IMAGETYPE_ICO */
if ($type == 2) {
$im = @imagecreatefromjpeg($file);
} elseif ($type == 1) {
$im = @imagecreatefromgif($file);
} elseif ($type == 3) {
$im = @imagecreatefrompng($file);
} elseif ($type == 15) {
$im = @imagecreatefromwbmp($file);
} elseif ($type == 6) {
$im = @imagecreatefrombmp($file);
} elseif ($type == 16) {
$im = @imagecreatefromxbm($file);
} else {
$im = @imagecreatefromstring(file_get_contents($file));
}
/*if ( $type == IMAGETYPE_JPEG ) {
$im = @imagecreatefromjpeg($file);
} elseif ( $type == IMAGETYPE_GIF ) {
$im = @imagecreatefromgif($file);
} elseif ( $type == IMAGETYPE_PNG ) {
$im = @imagecreatefrompng($file);
} elseif ( $type == IMAGETYPE_WBMP ) {
$im = @imagecreatefromwbmp($file);
} elseif ( $type == IMAGETYPE_BMP ) {
$im = @imagecreatefrombmp($file);
} elseif ( $type == IMAGETYPE_XBM ) {
$im = @imagecreatefromxbm($file);
} else {
$im = @imagecreatefromstring(file_get_contents($file));
}*/
if ($im !== false) {
return $im;
} else {
die(throwError("Unable to open_image"));
}
return false;
}
开发者ID:highchair,项目名称:hcd-trunk,代码行数:59,代码来源:image.php
示例5: readImage0
/**
* Read image via imagecreatefromxbm()
*
* @param string uri
* @return resource
* @throws img.ImagingException
*/
protected function readImage0($uri)
{
if (FALSE === ($r = imagecreatefromxbm($uri))) {
$e = new ImagingException('Cannot read image');
xp::gc(__FILE__);
throw $e;
}
return $r;
}
开发者ID:Gamepay,项目名称:xp-framework,代码行数:16,代码来源:XbmStreamReader.class.php
示例6: readImageFromUri
/**
* Read image
*
* @param string uri
* @return resource
* @throws img.ImagingException
*/
public function readImageFromUri($uri)
{
if (FALSE === ($r = imagecreatefromxbm($uri))) {
$e = new ImagingException('Cannot read image from "' . $uri . '"');
xp::gc(__FILE__);
throw $e;
}
return $r;
}
开发者ID:melogamepay,项目名称:xp-framework,代码行数:16,代码来源:XbmStreamReader.class.php
示例7: __construct
public function __construct($file, $width = null, $height = null)
{
if (!self::$_checked) {
self::check();
}
$this->_file = $file;
if (file_exists($this->_file)) {
$this->_realpath = realpath($this->_file);
$imageinfo = getimagesize($this->_file);
if ($imageinfo) {
$this->_width = $imageinfo[0];
$this->_height = $imageinfo[1];
$this->_type = $imageinfo[2];
$this->_mime = $imageinfo["mime"];
}
switch ($this->_type) {
case 1:
$this->_image = imagecreatefromgif($this->_file);
break;
case 2:
$this->_image = imagecreatefromjpeg($this->_file);
break;
case 3:
$this->_image = imagecreatefrompng($this->_file);
break;
case 15:
$this->_image = imagecreatefromwbmp($this->_file);
break;
case 16:
$this->_image = imagecreatefromxbm($this->_file);
break;
default:
if ($this->_mime) {
throw new Exception("Installed GD does not support " . $this->_mime . " images");
} else {
throw new Exception("Installed GD does not support such images");
}
break;
}
imagesavealpha($this->_image, true);
} else {
if (!$width || !$height) {
throw new Exception("Failed to create image from file " . $this->_file);
}
$this->_image = imagecreatetruecolor($width, $height);
imagealphablending($this->_image, true);
imagesavealpha($this->_image, true);
$this->_realpath = $this->_file;
$this->_width = $width;
$this->_height = $height;
$this->_type = 3;
$this->_mime = "image/png";
}
}
开发者ID:smallmirror62,项目名称:framework,代码行数:54,代码来源:Gd.php
示例8: image_resize
function image_resize($upfile, $output_filename, $output_path, $dst_w = 100, $dst_h = 100, $isRadio = 1, $trans_color = array(254, 254, 254))
{
$imagedata = GetImageSize($upfile);
// Read the size
$src_w = $imagedata[0];
$src_h = $imagedata[1];
$src_type = $imagedata[2];
$re_dst_x = 0;
$re_dst_y = 0;
if ($isRadio | 0 > 0) {
if ($dst_w >= $src_w && $dst_h >= $src_h) {
$re_dst_w = $src_w;
$re_dst_h = $src_h;
} else {
$p_w = $dst_w / $src_w;
$p_h = $dst_h / $src_h;
$p = min($p_w, $p_h);
$re_dst_w = $src_w * $p;
$re_dst_h = $src_h * $p;
}
} else {
$re_dst_w = $dst_w;
$re_dst_h = $dst_h;
}
if ($src_type == 1) {
$src_image = ImageCreateFromGif($upfile);
} else {
if ($src_type == 2) {
$src_image = ImageCreateFromJpeg($upfile);
} else {
if ($src_type == 3) {
$src_image = ImageCreateFromPng($upfile);
} else {
if ($src_type == 16) {
$src_image = imagecreatefromxbm($upfile);
}
}
}
}
//else if ($src_type==6)
// return;
$dst_image = imagecreatetruecolor($re_dst_w, $re_dst_h);
$bgc = imagecolorallocate($dst_image, $trans_color[0], $trans_color[1], $trans_color[2]);
imagefilledrectangle($dst_image, 0, 0, $re_dst_w, $re_dst_h, $bgc);
imagecolortransparent($dst_image, $bgc);
imagecopyresampled($dst_image, $src_image, $re_dst_x, $re_dst_y, 0, 0, $re_dst_w, $re_dst_h, $src_w, $src_h);
imagepng($dst_image, $output_path . $output_filename);
}
开发者ID:hardy419,项目名称:2015-7-27,代码行数:48,代码来源:lib_img_resize.php
示例9: __construct
function __construct($file_name)
{
$this->file_name = $file_name;
if (is_null(self::$load_image_funcs)) {
self::$load_image_funcs = array(IMAGETYPE_GIF => function ($fn) {
return imagecreatefromgif($fn);
}, IMAGETYPE_JPEG => function ($fn) {
return imagecreatefromjpeg($fn);
}, IMAGETYPE_PNG => function ($fn) {
return imagecreatefrompng($fn);
}, IMAGETYPE_WBMP => function ($fn) {
imagecreatefromwbmp($fn);
}, IMAGETYPE_XBM => function ($fn) {
imagecreatefromxbm($fn);
});
}
}
开发者ID:radialglo,项目名称:php,代码行数:17,代码来源:frame.php
示例10: _load
function _load($img)
{
if (!function_exists('imagecreate')) {
return false;
}
$dims = getimagesize($img);
if (empty($dims)) {
return false;
}
$this->OWIDTH = $this->WIDTH = $dims[0];
$this->OHEIGHT = $this->HEIGHT = $dims[1];
$this->FILENAME = $img;
$types = array(IMAGETYPE_GIF => 'GIF', IMAGETYPE_JPEG => 'JPEG', IMAGETYPE_PNG => 'PNG', IMAGETYPE_WBMP => 'WBMP', IMAGETYPE_XBM => 'XBM');
if (!isset($types[$dims[2]])) {
return false;
}
// unsupported type? TODO: maybe change this
$this->TYPE = $types[$dims[2]];
$this->typeGD = $dims[2];
if ($this->_img) {
imagedestroy($this->_img);
}
switch ($dims[2]) {
case IMAGETYPE_PNG:
$this->_img = imagecreatefrompng($img);
break;
case IMAGETYPE_JPEG:
$this->_img = imagecreatefromjpeg($img);
break;
case IMAGETYPE_GIF:
$this->_img = imagecreatefromgif($img);
break;
case IMAGETYPE_WBMP:
$this->_img = imagecreatefromwbmp($img);
break;
case IMAGETYPE_XBM:
$this->_img = imagecreatefromxbm($img);
break;
}
if (!$this->_img) {
return false;
}
return $this;
}
开发者ID:sammykumar,项目名称:TheVRForums,代码行数:44,代码来源:xt_image.php
示例11: getUrl
/**
* public method to get the url image and start the whole deal
*
* @param string $url
* @return void
* @access public
*/
public function getUrl($url)
{
$this->url = $url;
// We only want to get the headers, so do a HEAD request instead of GET (default)
$opts = array('http' => array('method' => 'HEAD'));
$context = stream_context_get_default($opts);
$this->headers = get_headers($this->url, 1);
if (strstr($this->headers[0], '200') !== FALSE) {
if ($this->headers['Content-Length'] < self::max_filesize) {
if ($this->is_image($this->headers['Content-Type']) !== FALSE) {
// Pretty self-explanatory - figure out which sort of image we're going to be processing and let GD know
switch ($this->headers['Content-Type']) {
case image_type_to_mime_type(IMAGETYPE_GIF):
$this->image = imagecreatefromgif($this->url);
break;
case image_type_to_mime_type(IMAGETYPE_JPEG):
$this->image = imagecreatefromjpeg($this->url);
break;
case image_type_to_mime_type(IMAGETYPE_PNG):
$this->image = imagecreatefrompng($this->url);
break;
/*case image_type_to_mime_type(IMAGETYPE_BMP):
$this->image = $this->imagecreatefrombmp($this->url);
break;*/
/*case image_type_to_mime_type(IMAGETYPE_BMP):
$this->image = $this->imagecreatefrombmp($this->url);
break;*/
case image_type_to_mime_type(IMAGETYPE_WBMP):
$this->image = imagecreatefromwbmp($this->url);
break;
case image_type_to_mime_type(IMAGETYPE_XBM):
$this->image = imagecreatefromxbm($this->url);
break;
default:
throw new customException($this->objLanguage->languageText('mod_utilties_unknown_format', 'utilities'));
//die('Something\'s gone horribly wrong...'); // If this happens scream very loudly and bang your head into a wall
break;
}
} else {
throw new customException($this->objLanguage->languageText('mod_utilties_unknown_format_cannotbedetermined', 'utilities'));
}
} else {
throw new customException($this->objLanguage->languageText('mod_utilties_filetoobig', 'utilities') . round(self::max_filesize / 1024) . 'KB.');
}
} else {
throw new customException($this->objLanguage->languageText('mod_utilties_urlnoaccess', 'utilities') . $this->url);
}
}
开发者ID:ookwudili,项目名称:chisimba,代码行数:55,代码来源:asciiart_class_inc.php
示例12: _forcedConvertPng
/**
* Convert uploaded file to PNG
*
* @param string $originalFile
* @param string $destinationFile
* @param int|null $originalImageType
* @return string
*/
protected function _forcedConvertPng($originalFile, $destinationFile, $originalImageType = null)
{
switch ($originalImageType) {
case IMAGETYPE_GIF:
$img = imagecreatefromgif($originalFile);
imagealphablending($img, false);
imagesavealpha($img, true);
break;
case IMAGETYPE_JPEG:
$img = imagecreatefromjpeg($originalFile);
break;
case IMAGETYPE_WBMP:
$img = imagecreatefromwbmp($originalFile);
break;
case IMAGETYPE_XBM:
$img = imagecreatefromxbm($originalFile);
break;
default:
return '';
}
imagepng($img, $destinationFile);
imagedestroy($img);
return $destinationFile;
}
开发者ID:barneydesmond,项目名称:propitious-octo-tribble,代码行数:32,代码来源:Images.php
示例13: resize
function resize($size, $x = 0, $y = 0, $w = null, $h = null)
{
$w = $w === null ? $this->width : $w;
$h = $h === null ? $this->height : $h;
if (!file_exists($this->filepath)) {
throw new Exception(_('Lost our file.'));
return;
}
// Don't crop/scale if it isn't necessary
if ($size === $this->width && $size === $this->height && $x === 0 && $y === 0 && $w === $this->width && $h === $this->height) {
$outname = Avatar::filename($this->id, image_type_to_extension($this->type), $size, common_timestamp());
$outpath = Avatar::path($outname);
@copy($this->filepath, $outpath);
return $outname;
}
switch ($this->type) {
case IMAGETYPE_GIF:
$image_src = imagecreatefromgif($this->filepath);
break;
case IMAGETYPE_JPEG:
$image_src = imagecreatefromjpeg($this->filepath);
break;
case IMAGETYPE_PNG:
$image_src = imagecreatefrompng($this->filepath);
break;
case IMAGETYPE_BMP:
$image_src = imagecreatefrombmp($this->filepath);
break;
case IMAGETYPE_WBMP:
$image_src = imagecreatefromwbmp($this->filepath);
break;
case IMAGETYPE_XBM:
$image_src = imagecreatefromxbm($this->filepath);
break;
default:
throw new Exception(_('Unknown file type'));
return;
}
$image_dest = imagecreatetruecolor($size, $size);
if ($this->type == IMAGETYPE_GIF || $this->type == IMAGETYPE_PNG || $this->type == IMAGETYPE_BMP) {
$transparent_idx = imagecolortransparent($image_src);
if ($transparent_idx >= 0) {
$transparent_color = imagecolorsforindex($image_src, $transparent_idx);
$transparent_idx = imagecolorallocate($image_dest, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
imagefill($image_dest, 0, 0, $transparent_idx);
imagecolortransparent($image_dest, $transparent_idx);
} elseif ($this->type == IMAGETYPE_PNG) {
imagealphablending($image_dest, false);
$transparent = imagecolorallocatealpha($image_dest, 0, 0, 0, 127);
imagefill($image_dest, 0, 0, $transparent);
imagesavealpha($image_dest, true);
}
}
imagecopyresampled($image_dest, $image_src, 0, 0, $x, $y, $size, $size, $w, $h);
if ($this->type == IMAGETYPE_BMP) {
//we don't want to save BMP... it's an inefficient, rare, antiquated format
//save png instead
$this->type = IMAGETYPE_PNG;
} else {
if ($this->type == IMAGETYPE_WBMP) {
//we don't want to save WBMP... it's a rare format that we can't guarantee clients will support
//save png instead
$this->type = IMAGETYPE_PNG;
} else {
if ($this->type == IMAGETYPE_XBM) {
//we don't want to save XBM... it's a rare format that we can't guarantee clients will support
//save png instead
$this->type = IMAGETYPE_PNG;
}
}
}
$outname = Avatar::filename($this->id, image_type_to_extension($this->type), $size, common_timestamp());
$outpath = Avatar::path($outname);
switch ($this->type) {
case IMAGETYPE_GIF:
imagegif($image_dest, $outpath);
break;
case IMAGETYPE_JPEG:
imagejpeg($image_dest, $outpath, 100);
break;
case IMAGETYPE_PNG:
imagepng($image_dest, $outpath);
break;
default:
throw new Exception(_('Unknown file type'));
return;
}
imagedestroy($image_src);
imagedestroy($image_dest);
return $outname;
}
开发者ID:stevertiqo,项目名称:StatusNet,代码行数:91,代码来源:imagefile.php
示例14: createImageFromFile
/**
* 跟據文件創建圖像GD 資源
* @param string $fileName 文件名
* @return gd resource
*/
public function createImageFromFile($fileName = NULL)
{
if (!$fileName) {
$fileName = $this->fileName;
$imgType = $this->imageType;
}
if (!is_readable($fileName) || !file_exists($fileName)) {
throw new Exception('Unable to open file "' . $fileName . '"');
}
if (!$imgType) {
$imageInfo = $this->getImageInfo($fileName);
$imgType = $imageInfo[2];
}
switch ($imgType) {
case IMAGETYPE_GIF:
$tempResource = imagecreatefromgif($fileName);
break;
case IMAGETYPE_JPEG:
$tempResource = imagecreatefromjpeg($fileName);
break;
case IMAGETYPE_PNG:
$tempResource = imagecreatefrompng($fileName);
break;
case IMAGETYPE_WBMP:
$tempResource = imagecreatefromwbmp($fileName);
break;
case IMAGETYPE_XBM:
$tempResource = imagecreatefromxbm($fileName);
break;
default:
throw new Exception('Unsupport image type');
}
return $tempResource;
}
开发者ID:austinliniware,项目名称:tsci-rota,代码行数:39,代码来源:Image.class.php
示例15: setBackground
/**
* Set the background of the CAPTCHA image
*
* @access private
*
*/
function setBackground()
{
imagefilledrectangle($this->im, 0, 0, $this->image_width * $this->iscale, $this->image_height * $this->iscale, $this->gdbgcolor);
imagefilledrectangle($this->tmpimg, 0, 0, $this->image_width * $this->iscale, $this->image_height * $this->iscale, $this->gdbgcolor);
if ($this->bgimg == '') {
if ($this->background_directory != null && is_dir($this->background_directory) && is_readable($this->background_directory)) {
$img = $this->getBackgroundFromDirectory();
if ($img != false) {
$this->bgimg = $img;
}
}
}
$dat = @getimagesize($this->bgimg);
if ($dat == false) {
return;
}
switch ($dat[2]) {
case 1:
$newim = @imagecreatefromgif($this->bgimg);
break;
case 2:
$newim = @imagecreatefromjpeg($this->bgimg);
break;
case 3:
$newim = @imagecreatefrompng($this->bgimg);
break;
case 15:
$newim = @imagecreatefromwbmp($this->bgimg);
break;
case 16:
$newim = @imagecreatefromxbm($this->bgimg);
break;
default:
return;
}
if (!$newim) {
return;
}
imagecopyresized($this->im, $newim, 0, 0, 0, 0, $this->image_width, $this->image_height, imagesx($newim), imagesy($newim));
}
开发者ID:uniquegel,项目名称:Feminnova,代码行数:46,代码来源:securimage.php
示例16: gdImageCreate
/**
* Create an gd image according to the specified mime type
*
* @param string $path image file
* @param string $mime
* @return gd image resource identifier
*/
protected function gdImageCreate($path, $mime)
{
switch ($mime) {
case 'image/jpeg':
return imagecreatefromjpeg($path);
case 'image/png':
return imagecreatefrompng($path);
case 'image/gif':
return imagecreatefromgif($path);
case 'image/xbm':
return imagecreatefromxbm($path);
}
return false;
}
开发者ID:radumargina,项目名称:webstyle-antcr,代码行数:21,代码来源:elFinderVolumeDriver.class.php
示例17: watermark
public function watermark($watermarkImage, $positionX = 0, $positionY = 0, $watermarkImageOpacity = 30, $repeat = false)
{
list($watermarkSrcWidth, $watermarkSrcHeight, $watermarkFileType, ) = getimagesize($watermarkImage);
$this->_getFileAttributes();
switch ($watermarkFileType) {
case IMAGETYPE_GIF:
$watermark = imagecreatefromgif($watermarkImage);
break;
case IMAGETYPE_JPEG:
$watermark = imagecreatefromjpeg($watermarkImage);
break;
case IMAGETYPE_PNG:
$watermark = imagecreatefrompng($watermarkImage);
break;
case IMAGETYPE_XBM:
$watermark = imagecreatefromxbm($watermarkImage);
break;
case IMAGETYPE_WBMP:
$watermark = imagecreatefromxbm($watermarkImage);
break;
default:
throw new Exception("Unsupported watermark image format.");
break;
}
if ($this->getWatermarkWidth() && $this->getWatermarkHeigth() && $this->getWatermarkPosition() != self::POSITION_STRETCH) {
$newWatermark = imagecreatetruecolor($this->getWatermarkWidth(), $this->getWatermarkHeigth());
imagealphablending($newWatermark, false);
$col = imagecolorallocate($newWatermark, 255, 255, 255);
imagefilledrectangle($newWatermark, 0, 0, $this->getWatermarkWidth(), $this->getWatermarkHeigth(), $col);
imagealphablending($newWatermark, true);
imagecopyresampled($newWatermark, $watermark, 0, 0, 0, 0, $this->getWatermarkWidth(), $this->getWatermarkHeigth(), imagesx($watermark), imagesy($watermark));
$watermark = $newWatermark;
}
if ($this->getWatermarkPosition() == self::POSITION_TILE) {
$repeat = true;
} elseif ($this->getWatermarkPosition() == self::POSITION_STRETCH) {
$newWatermark = imagecreatetruecolor($this->_imageSrcWidth, $this->_imageSrcHeight);
imagealphablending($newWatermark, false);
$col = imagecolorallocate($newWatermark, 255, 255, 255);
imagefilledrectangle($newWatermark, 0, 0, $this->_imageSrcWidth, $this->_imageSrcHeight, $col);
imagealphablending($newWatermark, true);
imagecopyresampled($newWatermark, $watermark, 0, 0, 0, 0, $this->_imageSrcWidth, $this->_imageSrcHeight, imagesx($watermark), imagesy($watermark));
$watermark = $newWatermark;
} elseif ($this->getWatermarkPosition() == self::POSITION_TOP_RIGHT) {
$positionX = $this->_imageSrcWidth - imagesx($watermark);
imagecopymerge($this->_imageHandler, $watermark, $positionX, $positionY, 0, 0, imagesx($watermark), imagesy($watermark), $watermarkImageOpacity);
} elseif ($this->getWatermarkPosition() == self::POSITION_BOTTOM_RIGHT) {
$positionX = $this->_imageSrcWidth - imagesx($watermark);
$positionY = $this->_imageSrcHeight - imagesy($watermark);
imagecopymerge($this->_imageHandler, $watermark, $positionX, $positionY, 0, 0, imagesx($watermark), imagesy($watermark), $watermarkImageOpacity);
} elseif ($this->getWatermarkPosition() == self::POSITION_BOTTOM_LEFT) {
$positionY = $this->_imageSrcHeight - imagesy($watermark);
imagecopymerge($this->_imageHandler, $watermark, $positionX, $positionY, 0, 0, imagesx($watermark), imagesy($watermark), $watermarkImageOpacity);
}
if ($repeat === false) {
imagecopymerge($this->_imageHandler, $watermark, $positionX, $positionY, 0, 0, imagesx($watermark), imagesy($watermark), $watermarkImageOpacity);
} else {
$offsetX = $positionX;
$offsetY = $positionY;
while ($offsetY <= $this->_imageSrcHeight + imagesy($watermark)) {
while ($offsetX <= $this->_imageSrcWidth + imagesx($watermark)) {
imagecopymerge($this->_imageHandler, $watermark, $offsetX, $offsetY, 0, 0, imagesx($watermark), imagesy($watermark), $watermarkImageOpacity);
$offsetX += imagesx($watermark);
}
$offsetX = $positionX;
$offsetY += imagesy($watermark);
}
}
imagedestroy($watermark);
$this->refreshImageDimensions();
}
开发者ID:arslbbt,项目名称:mangentovies,代码行数:71,代码来源:Gd2.php
示例18: draw
/**
* 画出验证码图片
*
* @param int $width 验证码图片宽度
* @param int $height 验证码图片高度
* @param string $bg 附加背景图地址
* @return string 返回验证码
*/
function draw($width = 120, $height = 60, $bg = '')
{
/**
* 设置颜色
*/
$image = imagecreatetruecolor($width, $height) or die('Cannot initialize new GD image stream');
$nscolor = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
//干扰颜色
if (empty($this->bgcolor)) {
$bgcolor = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
//背景颜色
} else {
$rgb = $this->html2rgb($this->bgcolor);
$bgcolor = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
}
imagefilledrectangle($image, 0, 0, $width, $height, $bgcolor);
//设置背景颜色
/**
* 背景处理
*/
$this->background = $bg ? $bg : $this->background;
if ($this->background && file_exists($this->background)) {
$dat = getimagesize($this->background);
switch ($dat[2]) {
case 1:
$newim = imagecreatefromgif($this->background);
break;
case 2:
$newim = imagecreatefromjpeg($this->background);
break;
case 3:
$newim = imagecreatefrompng($this->background);
break;
case 15:
$newim = imagecreatefromwbmp($this->background);
break;
case 16:
$newim = imagecreatefromxbm($this->background);
break;
default:
$newim = null;
}
/**
* 将背景合成到验证码图片中
*/
if ($newim) {
if ($this->copy_bg_width <= 0) {
$this->copy_bg_width = $width;
}
if ($this->copy_bg_height <= 0) {
$this->copy_bg_height = $height;
}
imagecopyresampled($image, $newim, 0, 0, 0, 0, $this->copy_bg_width, $this->copy_bg_height, imagesx($newim), imagesy($newim));
}
} else {
for ($i = 0; $i < $this->disturb_size; $i++) {
imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $nscolor);
}
for ($i = 0; $i < $this->disturb_size; $i++) {
imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $nscolor);
}
}
/**
* 创建文本框与文本
*/
if (empty($this->words)) {
$this->generate_words();
}
$font_size = $this->font_size ? $this->font_size : ceil(($width + $height) / 2 * 0.36);
$textbox = imagettfbbox($font_size, 0, $this->font, $this->words) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4]) / 2;
if ($this->text_margin_top > 0) {
$y = $this->text_margin_top;
//固定字母对象顶边的外延边距
} else {
$y = ($height - $textbox[5]) / 2;
//不固定字母对象顶边的外延边距
}
/**
* 生成字母并定位置
*/
$strlen = strlen($this->words);
for ($i = 0; $i < $strlen; ++$i) {
$text_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $this->words[$i]);
$x = $x + $font_size / 1.3;
if ($this->text_margin_top <= 0) {
$y = rand($y - $height / 5, $y + $height / 5);
}
}
/**
* 输出图片
//.........这里部分代码省略.........
开发者ID:laiello,项目名称:hecart,代码行数:101,代码来源:verify.php
示例19: loadFromFile
/**
* @brief Loads an image from a local file.
* @param $imageref The path to a local file.
* @returns An image resource or false on error
*/
public function loadFromFile($imagePath = false)
{
// exif_imagetype throws "read error!" if file is less than 12 byte
if (!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) {
// Debug output disabled because this method is tried before loadFromBase64?
OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: ' . $imagePath, OC_Log::DEBUG);
return false;
}
$iType = exif_imagetype($imagePath);
switch ($iType) {
case IMAGETYPE_GIF:
if (imagetypes() & IMG_GIF) {
$this->resource = imagecreatefromgif($imagePath);
} else {
OC_Log::write('core', 'OC_Image->loadFromFile, GIF images not supported: ' . $imagePath, OC_Log::DEBUG);
}
break;
case IMAGETYPE_JPEG:
if (imagetypes() & IMG_JPG) {
$this->resource = imagecreatefromjpeg($imagePath);
} else {
OC_Log::write('core', 'OC_Image->loadFromFile, JPG images not supported: ' . $imagePath, OC_Log::DEBUG);
}
break;
case IMAGETYPE_PNG:
if (imagetypes() & IMG_PNG) {
$this->resource = imagecreatefrompng($imagePath);
} else {
OC_Log::write('core', 'OC_Image->loadFromFile, PNG images not supported: ' . $imagePath, OC_Log::DEBUG);
}
break;
case IMAGETYPE_XBM:
if (imagetypes() & IMG_XPM) {
$this->resource = imagecreatefromxbm($imagePath);
} else {
OC_Log::write('core', 'OC_Image->loadFromFile, XBM/XPM images not supported: ' . $imagePath, OC_Log::DEBUG);
}
break;
case IMAGETYPE_WBMP:
if (imagetypes() & IMG_WBMP) {
$this->resource = imagecreatefromwbmp($imagePath);
} else {
OC_Log::write('core', 'OC_Image->loadFromFile, WBMP images not supported: ' . $imagePath, OC_Log::DEBUG);
}
break;
case IMAGETYPE_BMP:
$this->resource = $this->imagecreatefrombmp($imagePath);
break;
/*
case IMAGETYPE_TIFF_II: // (intel byte order)
break;
case IMAGETYPE_TIFF_MM: // (motorola byte order)
break;
case IMAGETYPE_JPC:
break;
case IMAGETYPE_JP2:
break;
case IMAGETYPE_JPX:
break;
case IMAGETYPE_JB2:
break;
case IMAGETYPE_SWC:
break;
case IMAGETYPE_IFF:
break;
case IMAGETYPE_ICO:
break;
case IMAGETYPE_SWF:
break;
case IMAGETYPE_PSD:
break;
*/
/*
case IMAGETYPE_TIFF_II: // (intel byte order)
break;
case IMAGETYPE_TIFF_MM: // (motorola byte order)
break;
case IMAGETYPE_JPC:
break;
case IMAGETYPE_JP2:
break;
case IMAGETYPE_JPX:
break;
case IMAGETYPE_JB2:
break;
case IMAGETYPE_SWC:
break;
case IMAGETYPE_IFF:
break;
case IMAGETYPE_ICO:
break;
case IMAGETYPE_SWF:
break;
case IMAGETYPE_PSD:
break;
//.........这里部分代码省略.........
开发者ID:hjimmy,项目名称:owncloud,代码行数:101,代码来源:image.php
|
请发表评论