本文整理汇总了PHP中phpthumb_functions::ImageCreateFunction方法的典型用法代码示例。如果您正苦于以下问题:PHP phpthumb_functions::ImageCreateFunction方法的具体用法?PHP phpthumb_functions::ImageCreateFunction怎么用?PHP phpthumb_functions::ImageCreateFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpthumb_functions
的用法示例。
在下文中一共展示了phpthumb_functions::ImageCreateFunction方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: elseif
$phpThumb->phpThumbDebug();
}
////////////////////////////////////////////////////////////////
if ($phpThumb->rawImageData) {
// great
} elseif (@$_GET['new']) {
// generate a blank image resource of the specified size/background color/opacity
if ($phpThumb->w <= 0 || $phpThumb->h <= 0) {
$phpThumb->ErrorImage('"w" and "h" parameters required for "new"');
}
@(list($bghexcolor, $opacity) = explode('|', $_GET['new']));
if (!phpthumb_functions::IsHexColor($bghexcolor)) {
$phpThumb->ErrorImage('BGcolor parameter for "new" is not valid');
}
$opacity = strlen($opacity) ? $opacity : 100;
if ($phpThumb->gdimg_source = phpthumb_functions::ImageCreateFunction($phpThumb->w, $phpThumb->h)) {
$alpha = (100 - min(100, max(0, $opacity))) * 1.27;
if ($alpha) {
$phpThumb->setParameter('is_alpha', true);
ImageAlphaBlending($phpThumb->gdimg_source, false);
ImageSaveAlpha($phpThumb->gdimg_source, true);
}
$new_background_color = phpthumb_functions::ImageHexColorAllocate($phpThumb->gdimg_source, $bghexcolor, false, $alpha);
ImageFilledRectangle($phpThumb->gdimg_source, 0, 0, $phpThumb->w, $phpThumb->h, $new_background_color);
} else {
$phpThumb->ErrorImage('failed to create "new" image (' . $phpThumb->w . 'x' . $phpThumb->h . ')');
}
} elseif (!$phpThumb->src) {
$phpThumb->ErrorImage('Usage: ' . $_SERVER['PHP_SELF'] . '?src=/path/and/filename.jpg' . "\n" . 'read Usage comments for details');
} elseif (preg_match('/^(f|ht)tp\\:\\/\\//i', $phpThumb->src)) {
$phpThumb->DebugMessage('$phpThumb->src (' . $phpThumb->src . ') is remote image, attempting to download', __FILE__, __LINE__);
示例2: WatermarkOverlay
public function WatermarkOverlay(&$gdimg_dest, &$img_watermark, $alignment = '*', $opacity = 50, $margin_x = 5, $margin_y = null)
{
if (is_resource($gdimg_dest) && is_resource($img_watermark)) {
$watermark_source_x = 0;
$watermark_source_y = 0;
$img_source_width = ImageSX($gdimg_dest);
$img_source_height = ImageSY($gdimg_dest);
$watermark_source_width = ImageSX($img_watermark);
$watermark_source_height = ImageSY($img_watermark);
$watermark_opacity_percent = max(0, min(100, $opacity));
$margin_y = is_null($margin_y) ? $margin_x : $margin_y;
$watermark_margin_x = $margin_x > 0 && $margin_x < 1 ? round((1 - $margin_x) * $img_source_width) : $margin_x;
$watermark_margin_y = $margin_y > 0 && $margin_y < 1 ? round((1 - $margin_y) * $img_source_height) : $margin_y;
if (preg_match('#^([0-9\\.\\-]*)x([0-9\\.\\-]*)$#i', $alignment, $matches)) {
$watermark_destination_x = intval($matches[1]);
$watermark_destination_y = intval($matches[2]);
} else {
switch ($alignment) {
case '*':
if ($gdimg_tiledwatermark = phpthumb_functions::ImageCreateFunction($img_source_width, $img_source_height)) {
ImageAlphaBlending($gdimg_tiledwatermark, false);
ImageSaveAlpha($gdimg_tiledwatermark, true);
$text_color_transparent = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg_tiledwatermark, 255, 0, 255, 127);
ImageFill($gdimg_tiledwatermark, 0, 0, $text_color_transparent);
// set the tiled image transparent color to whatever the untiled image transparency index is
// ImageColorTransparent($gdimg_tiledwatermark, ImageColorTransparent($img_watermark));
// a "cleaner" way of doing it, but can't handle the margin feature :(
// ImageSetTile($gdimg_tiledwatermark, $img_watermark);
// ImageFill($gdimg_tiledwatermark, 0, 0, IMG_COLOR_TILED);
// break;
// ImageFill($gdimg_tiledwatermark, 0, 0, ImageColorTransparent($gdimg_tiledwatermark));
// tile the image as many times as can fit
for ($x = $watermark_margin_x; $x < $img_source_width + $watermark_source_width; $x += $watermark_source_width + $watermark_margin_x) {
for ($y = $watermark_margin_y; $y < $img_source_height + $watermark_source_height; $y += $watermark_source_height + $watermark_margin_y) {
ImageCopy($gdimg_tiledwatermark, $img_watermark, $x, $y, 0, 0, min($watermark_source_width, $img_source_width - $x - $watermark_margin_x), min($watermark_source_height, $img_source_height - $y - $watermark_margin_y));
}
}
$watermark_source_width = ImageSX($gdimg_tiledwatermark);
$watermark_source_height = ImageSY($gdimg_tiledwatermark);
$watermark_destination_x = 0;
$watermark_destination_y = 0;
ImageDestroy($img_watermark);
$img_watermark = $gdimg_tiledwatermark;
}
break;
case 'T':
$watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2 + $watermark_margin_x);
$watermark_destination_y = $watermark_margin_y;
break;
case 'B':
$watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2 + $watermark_margin_x);
$watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y;
break;
case 'L':
$watermark_destination_x = $watermark_margin_x;
$watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2 + $watermark_margin_y);
break;
case 'R':
$watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x;
$watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2 + $watermark_margin_y);
break;
case 'C':
$watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2);
$watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2);
break;
case 'TL':
$watermark_destination_x = $watermark_margin_x;
$watermark_destination_y = $watermark_margin_y;
break;
case 'TR':
$watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x;
$watermark_destination_y = $watermark_margin_y;
break;
case 'BL':
//echo '<pre>';
////var_dump($watermark_destination_x);
////var_dump($watermark_destination_y);
//var_dump($watermark_margin_x);
//var_dump($img_source_height);
//var_dump($watermark_source_height);
//var_dump($watermark_margin_y);
$watermark_destination_x = $watermark_margin_x;
$watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y;
break;
case 'BR':
default:
$watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x;
$watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y;
break;
}
}
ImageAlphaBlending($gdimg_dest, false);
ImageSaveAlpha($gdimg_dest, true);
ImageSaveAlpha($img_watermark, true);
phpthumb_functions::ImageCopyRespectAlpha($gdimg_dest, $img_watermark, $watermark_destination_x, $watermark_destination_y, 0, 0, $watermark_source_width, $watermark_source_height, $watermark_opacity_percent);
return true;
}
return false;
}
示例3: WatermarkOverlay
function WatermarkOverlay(&$gdimg_dest, &$img_watermark, $alignment = '*', $opacity = 50, $margin = 5)
{
if (is_resource($gdimg_dest) && is_resource($img_watermark)) {
$watermark_source_x = 0;
$watermark_source_y = 0;
$img_source_width = ImageSX($gdimg_dest);
$img_source_height = ImageSY($gdimg_dest);
$watermark_source_width = ImageSX($img_watermark);
$watermark_source_height = ImageSY($img_watermark);
$watermark_opacity_percent = max(0, min(100, $opacity));
if ($margin < 1) {
$watermark_margin_percent = 1 - $margin;
} else {
$watermark_margin_percent = (100 - max(0, min(100, $margin))) / 100;
}
$watermark_margin_x = round((1 - $watermark_margin_percent) * $img_source_width);
$watermark_margin_y = round((1 - $watermark_margin_percent) * $img_source_height);
switch ($alignment) {
case '*':
if ($gdimg_tiledwatermark = phpthumb_functions::ImageCreateFunction($img_source_width, $img_source_height)) {
ImageAlphaBlending($gdimg_tiledwatermark, false);
if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=')) {
ImageSaveAlpha($gdimg_tiledwatermark, true);
}
$text_color_transparent = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg_tiledwatermark, 255, 0, 255, 127);
ImageFill($gdimg_tiledwatermark, 0, 0, $text_color_transparent);
// set the tiled image transparent color to whatever the untiled image transparency index is
// ImageColorTransparent($gdimg_tiledwatermark, ImageColorTransparent($img_watermark));
// a "cleaner" way of doing it, but can't handle the margin feature :(
// ImageSetTile($gdimg_tiledwatermark, $img_watermark);
// ImageFill($gdimg_tiledwatermark, 0, 0, IMG_COLOR_TILED);
// break;
// ImageFill($gdimg_tiledwatermark, 0, 0, ImageColorTransparent($gdimg_tiledwatermark));
// tile the image as many times as can fit
for ($x = $watermark_margin_x; $x < $img_source_width + $watermark_source_width; $x += round($watermark_source_width + (1 - $watermark_margin_percent) * $img_source_width)) {
for ($y = $watermark_margin_y; $y < $img_source_height + $watermark_source_height; $y += round($watermark_source_height + (1 - $watermark_margin_percent) * $img_source_height)) {
ImageCopy($gdimg_tiledwatermark, $img_watermark, $x, $y, 0, 0, min($watermark_source_width, $img_source_width - $x - (1 - $watermark_margin_percent) * $img_source_width), min($watermark_source_height, $img_source_height - $y - (1 - $watermark_margin_percent) * $img_source_height));
}
}
$watermark_source_width = ImageSX($gdimg_tiledwatermark);
$watermark_source_height = ImageSY($gdimg_tiledwatermark);
$watermark_destination_x = 0;
$watermark_destination_y = 0;
ImageDestroy($img_watermark);
$img_watermark = $gdimg_tiledwatermark;
}
break;
case 'T':
$watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2 + $watermark_margin_x);
$watermark_destination_y = $watermark_margin_y;
break;
case 'B':
$watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2 + $watermark_margin_x);
$watermark_destination_y = round(($img_source_height - $watermark_source_height) * $watermark_margin_percent);
break;
case 'L':
$watermark_destination_x = $watermark_margin_x;
$watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2 + $watermark_margin_y);
break;
case 'R':
$watermark_destination_x = round(($img_source_width - $watermark_source_width) * $watermark_margin_percent);
$watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2 + $watermark_margin_y);
break;
case 'C':
$watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2);
$watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2);
break;
case 'TL':
$watermark_destination_x = $watermark_margin_x;
$watermark_destination_y = $watermark_margin_y;
break;
case 'TR':
$watermark_destination_x = round(($img_source_width - $watermark_source_width) * $watermark_margin_percent);
$watermark_destination_y = $watermark_margin_y;
break;
case 'BL':
$watermark_destination_x = $watermark_margin_x;
$watermark_destination_y = round(($img_source_height - $watermark_source_height) * $watermark_margin_percent);
break;
case 'BR':
default:
$watermark_destination_x = round(($img_source_width - $watermark_source_width) * $watermark_margin_percent);
$watermark_destination_y = round(($img_source_height - $watermark_source_height) * $watermark_margin_percent);
break;
}
ImageAlphaBlending($gdimg_dest, false);
if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=')) {
ImageSaveAlpha($gdimg_dest, true);
ImageSaveAlpha($img_watermark, true);
}
phpthumb_functions::ImageCopyRespectAlpha($gdimg_dest, $img_watermark, $watermark_destination_x, $watermark_destination_y, 0, 0, $watermark_source_width, $watermark_source_height, $watermark_opacity_percent);
return true;
}
return false;
}
示例4: CreateGDoutput
function CreateGDoutput()
{
$this->CalculateThumbnailDimensions();
// Create the GD image (either true-color or 256-color, depending on GD version)
$this->gdimg_output = phpthumb_functions::ImageCreateFunction($this->thumbnail_width, $this->thumbnail_height);
// Images that have transparency must have the background filled with the configured 'bg' color
// otherwise the transparent color will appear as black
ImageSaveAlpha($this->gdimg_output, true);
if ($this->is_alpha && phpthumb_functions::gd_version() >= 2) {
ImageAlphaBlending($this->gdimg_output, false);
$output_full_alpha = phpthumb_functions::ImageColorAllocateAlphaSafe($this->gdimg_output, 255, 255, 255, 127);
ImageFilledRectangle($this->gdimg_output, 0, 0, $this->thumbnail_width, $this->thumbnail_height, $output_full_alpha);
} else {
$current_transparent_color = ImageColorTransparent($this->gdimg_source);
if ($this->bg || @$current_transparent_color >= 0) {
$this->config_background_hexcolor = $this->bg ? $this->bg : $this->config_background_hexcolor;
if (!phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
return $this->ErrorImage('Invalid hex color string "' . $this->config_background_hexcolor . '" for parameter "bg"');
}
$background_color = phpthumb_functions::ImageHexColorAllocate($this->gdimg_output, $this->config_background_hexcolor);
ImageFilledRectangle($this->gdimg_output, 0, 0, $this->thumbnail_width, $this->thumbnail_height, $background_color);
}
}
$this->DebugMessage('CreateGDoutput() returning canvas "' . $this->thumbnail_width . 'x' . $this->thumbnail_height . '"', __FILE__, __LINE__);
return true;
}
示例5: WatermarkText
//.........这里部分代码省略.........
case 'BL':
// no change neccesary
break;
case 'C':
case 'T':
case 'B':
$text_origin_x = $originOffsetX ? $originOffsetX - round($text_width_line / 2) : round((ImageSX($gdimg) - $text_width_line) / 2);
break;
case 'R':
case 'TR':
case 'BR':
$text_origin_x = $originOffsetX ? $originOffsetX - $text_width_line : ImageSX($gdimg) - $text_width_line + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
break;
}
//ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y, $letter_color_text, $ttffont, $text);
$this->DebugMessage('WatermarkText() calling ImageTTFtext($gdimg, ' . $size . ', ' . $angle . ', ' . $text_origin_x . ', ' . ($text_origin_y + $y_offset) . ', $letter_color_text, ' . $ttffont . ', ' . $line . ')', __FILE__, __LINE__);
$this->shadow_text($gdimg, $size, $angle, $text_origin_x, $text_origin_y + $y_offset, $ttffont, $line, $opacity);
// ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y + $y_offset, $letter_color_text, $ttffont, $line);
$y_offset += $char_height;
}
}
return $that;
// return true;
} else {
//TODO FIX and Test.
$size = min(5, max(1, $size));
$this->DebugMessage('Using built-in font (size=' . $size . ') for text watermark' . ($ttffont ? ' because $ttffont !is_readable(' . $ttffont . ')' : ''), __FILE__, __LINE__);
$text_width = 0;
$text_height = 0;
foreach ($textlines as $dummy => $line) {
$text_width = max($text_width, ImageFontWidth($size) * strlen($line));
$text_height += ImageFontHeight($size);
}
if ($img_watermark = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
ImageAlphaBlending($img_watermark, false);
if (phpthumb_functions::IsHexColor($bg_color)) {
$text_background_alpha = round(127 * ((100 - min(max(0, $bg_opacity), 100)) / 100));
$text_color_background = phpthumb_functions::ImageHexColorAllocate($img_watermark, $bg_color, false, $text_background_alpha);
} else {
$text_color_background = phpthumb_functions::ImageHexColorAllocate($img_watermark, 'FFFFFF', false, 127);
}
$this->DebugMessage('WatermarkText() calling ImageFilledRectangle($img_watermark, 0, 0, ' . ImageSX($img_watermark) . ', ' . ImageSY($img_watermark) . ', $text_color_background)', __FILE__, __LINE__);
ImageFilledRectangle($img_watermark, 0, 0, ImageSX($img_watermark), ImageSY($img_watermark), $text_color_background);
if ($angle && function_exists('ImageRotate')) {
// using $img_watermark_mask is pointless if ImageRotate function isn't available
if ($img_watermark_mask = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
$mask_color_background = ImageColorAllocate($img_watermark_mask, 0, 0, 0);
ImageAlphaBlending($img_watermark_mask, false);
ImageFilledRectangle($img_watermark_mask, 0, 0, ImageSX($img_watermark_mask), ImageSY($img_watermark_mask), $mask_color_background);
$mask_color_watermark = ImageColorAllocate($img_watermark_mask, 255, 255, 255);
}
}
$text_color_watermark = phpthumb_functions::ImageHexColorAllocate($img_watermark, $hex_color);
foreach ($textlines as $key => $line) {
switch ($alignment) {
case 'C':
$x_offset = round(($text_width - ImageFontWidth($size) * strlen($line)) / 2);
$originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
$originOffsetY = (ImageSY($gdimg) - ImageSY($img_watermark)) / 2;
break;
case 'T':
$x_offset = round(($text_width - ImageFontWidth($size) * strlen($line)) / 2);
$originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
$originOffsetY = $margin;
break;
case 'B':