本文整理汇总了PHP中imageGif函数的典型用法代码示例。如果您正苦于以下问题:PHP imageGif函数的具体用法?PHP imageGif怎么用?PHP imageGif使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imageGif函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* 生成された画像を保存する
*
* @return boolean
* @access public
* @static
*/
function save()
{
//保存先のディレクトリが存在しているかチェック
$filePath = dirname($this->dstPath);
if (!file_exists($filePath)) {
mkdir($filePath);
}
if ($this->imageType == 'image/jpeg') {
return imageJpeg($this->dstImage, $this->dstPath, $this->quality);
} elseif ($this->imageType == 'image/gif') {
return imageGif($this->dstImage, $this->dstPath);
} elseif ($this->imageType == 'image/png') {
return imagePng($this->dstImage, $this->dstPath);
}
}
示例2: CreateGifThumbnail
public static function CreateGifThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth)
{
$srcImg = ImageCreateFromGif($imageDirectory . $imageName);
$origWidth = imagesx($srcImg);
$origHeight = imagesy($srcImg);
$ratio = $thumbWidth / $origWidth;
$thumbHeight = $origHeight * $ratio;
$thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($srcImg), imagesy($srcImg));
imageGif($thumbImg, $thumbDirectory . "tn_" . $imageName);
}
示例3: saveFile
public static function saveFile($image = null, $destFile = null, $saveType = self::SAVE_JPG)
{
switch ($saveType) {
case self::SAVE_GIF:
return @imageGif($image, $destFile);
case self::SAVE_JPG:
return @imageJpeg($image, $destFile, self::SAVE_QUALITY);
case self::SAVE_PNG:
return @imagePng($image, $destFile);
default:
return false;
}
}
示例4: AnimatedOut
function AnimatedOut()
{
for ($i = 0; $i < ANIM_FRAMES; $i++) {
$image = imageCreateTrueColor(imageSX($this->image), imageSY($this->image));
if (imageCopy($image, $this->image, 0, 0, 0, 0, imageSX($this->image), imageSY($this->image))) {
Captcha::DoNoise($image, 200, 0);
Ob_Start();
imageGif($image);
imageDestroy($image);
$f_arr[] = Ob_Get_Contents();
$d_arr[] = ANIM_DELAYS;
Ob_End_Clean();
}
}
$GIF = new GIFEncoder($f_arr, $d_arr, 0, 2, -1, -1, -1, 'C_MEMORY');
return $GIF->GetAnimation();
}
示例5: createNewImage
private function createNewImage($newImg, $newName, $imgInfo)
{
switch ($imgInfo["type"]) {
case 1:
//gif
$result = imageGif($newImg, $this->path . $newName);
break;
case 2:
//jpg
$result = imageJPEG($newImg, $this->path . $newName);
break;
case 3:
//png
$return = imagepng($newImg, $this->path . $newName);
break;
}
imagedestroy($newImg);
return $newName;
}
示例6: resizeImage
function resizeImage($file, $max_x, $max_y, $forcePng = false)
{
if ($max_x <= 0 || $max_y <= 0) {
$max_x = 5;
$max_y = 5;
}
$src = BASEDIR . '/avatars/' . $file;
list($width, $height, $type) = getImageSize($src);
$scale = min($max_x / $width, $max_y / $height);
$newWidth = $width * $scale;
$newHeight = $height * $scale;
$img = imagecreatefromstring(file_get_contents($src));
$black = imagecolorallocate($img, 0, 0, 0);
$resizedImage = imageCreateTrueColor($newWidth, $newHeight);
imagecolortransparent($resizedImage, $black);
imageCopyResampled($resizedImage, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imageDestroy($img);
unlink($src);
if (!$forcePng) {
switch ($type) {
case IMAGETYPE_JPEG:
imageJpeg($resizedImage, BASEDIR . '/avatars/' . $file);
break;
case IMAGETYPE_GIF:
imageGif($resizedImage, BASEDIR . '/avatars/' . $file);
break;
case IMAGETYPE_PNG:
imagePng($resizedImage, BASEDIR . '/avatars/' . $file);
break;
default:
imagePng($resizedImage, BASEDIR . '/avatars/' . $file);
break;
}
} else {
imagePng($resizedImage, BASEDIR . '/avatars/' . $file . '.png');
}
return;
}
示例7: save
function save($filename, $type = 'png', $quality = 100)
{
$this->_build();
$this->_build_border();
switch ($type) {
case 'gif':
$ret = imageGif($this->_dest_image, $filename);
break;
case 'jpg':
case 'jpeg':
$ret = imageJpeg($this->_dest_image, $filename, $quality);
break;
case 'png':
$ret = imagePng($this->_dest_image, $filename);
break;
default:
$this->_error('Save: Invalid Format');
break;
}
if (!$ret) {
$this->_error('Save: Unable to save');
}
}
示例8: substr
$alphabet = '1234567890abcdefghijkmnpqrstuvwxyz';
$string = substr(str_shuffle(str_repeat($alphabet, $length)), 0, $length);
//���������� �����
$img = imagecreate(140, 50);
//������� ��������
if ($color == "red") {
$color = imagecolorAllocate($img, 249, 183, 169);
$border_color = imagecolorAllocate($img, 212, 12, 12);
} else {
$color = imagecolorAllocate($img, 217, 239, 185);
$border_color = imagecolorAllocate($img, 160, 214, 81);
}
$text_color = imagecolorAllocate($img, 102, 102, 102);
$�� = (imageSX($img) - 1 * strlen($string)) / 2;
imagettftext($img, 23, -3, 10, 30, $text_color, 'font.TTF', $string);
imageGif($img, "img/number.gif");
imageDestroy($img);
$_SESSION["capcha"] = $string;
?>
<div class="loginform" <?php
if ($_SESSION['try'] > $num_for_lock) {
echo 'style="background:url(../img/lock.png) no-repeat 60% 30%;"';
}
?>
>
<form method="post" action="index.php" >
<fieldset >
<p>
<label for="login" class="top">����:</label><br />
<input type="text" name="login" id="login" tabindex="1" class="field" value="<?php
echo $_POST['login'];
示例9: session_start
<?php
session_start();
$alpha = "0123456789";
$secret = "";
$old_user_id;
for ($i = 0; $i < 5; $i++) {
$secret .= $alpha[rand(0, strlen($alpha) - 1)];
}
$_SESSION['secret'] = $secret;
$im = imagecreate(80, 31);
imageColorAllocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 10, 10, $secret, $textcolor);
imageGif($im);
header("Content-Type: image/gif");
示例10: imageResize
//.........这里部分代码省略.........
if ($params["WIDTH"] == 55 && $params["HEIGHT"] == 45)
{
imageAlphaBlending($im, true);
$waterMark = ImageCreateFromPng($_SERVER["DOCUMENT_ROOT"] . "/img/video.png");
imageCopyResampled($im, $waterMark, 0, 0, 0, 0, $params["WIDTH"], $params["HEIGHT"], $params["WIDTH"], $params["HEIGHT"]);
}
break;
case 'width' :
$factor = $i[1] / $i[0]; // определяем пропорцию height / width
if ($factor > 1.35)
{
$pn["WIDTH"] = $params["WIDTH"];
$scale_factor = $i[0] / $pn["WIDTH"]; // коэфффициент масштабирования
$pn["HEIGHT"] = ceil($i[1] / $scale_factor);
$x = 0;
$y = 0;
if (($params["HEIGHT"] / $pn["HEIGHT"]) < 0.6)
{
//echo 100 / ($pn["HEIGHT"] * 100) / ($params["HEIGHT"] *1.5);
$pn["HEIGHT"] = (100 / (($pn["HEIGHT"] * 100) / ($params["HEIGHT"] * 1.3))) * $pn["HEIGHT"];
$newKoef = $i[1] / $pn["HEIGHT"];
$pn["WIDTH"] = $i[0] / $newKoef;
$x = ($params["WIDTH"] - $pn["WIDTH"]) / 2;
//$y = ($params["HEIGHT"] - $pn["HEIGHT"]) / 2;
}
imageCopyResampled($im, $i0, $x, $y, 0, 0, $pn["WIDTH"], $pn["HEIGHT"], $i[0], $i[1]);
}
else
{
if (($i [0] < $params["WIDTH"]) && ($i [1] < $params["HEIGHT"]))
{
$k_x = 1;
$k_y = 1;
}
else
{
$k_x = $i [0] / $params["WIDTH"];
$k_y = $i [1] / $params["HEIGHT"];
}
if ($k_x < $k_y)
$k = $k_y;
else
$k = $k_x;
$pn["WIDTH"] = $i [0] / $k;
$pn["HEIGHT"] = $i [1] / $k;
$x = ($params["WIDTH"] - $pn["WIDTH"]) / 2;
$y = ($params["HEIGHT"] - $pn["HEIGHT"]) / 2;
imageCopyResampled($im, $i0, $x, $y, 0, 0, $params["MODE"], $pn["HEIGHT"], $i[0], $i[1]);
}
break;
default : imageCopyResampled($im, $i0, 0, 0, 0, 0, $params["WIDTH"], $params["HEIGHT"], $i[0], $i[1]);
break;
}
if ($params["HIQUALITY"])
{
$sharpenMatrix = array
(
array(-1.2, -1, -1.2),
array(-1, 20, -1),
array(-1.2, -1, -1.2)
);
// calculate the sharpen divisor
$divisor = array_sum(array_map('array_sum', $sharpenMatrix));
$offset = 0;
// apply the matrix
imageconvolution($im, $sharpenMatrix, $divisor, $offset);
}
switch (strtolower($imageType))
{
case 'gif' :imageSaveAlpha($im, true);
@imageGif($im, CHACHE_IMG_PATH . $pathToFile);
break;
case 'jpg' : case 'jpeg' : @imageJpeg($im, CHACHE_IMG_PATH . $pathToFile, $params["QUALITY"]);
break;
case 'png' : imageSaveAlpha($im, true);
@imagePng($im, CHACHE_IMG_PATH . $pathToFile);
break;
}
}
else
{
copy($pathToOriginalFile, CHACHE_IMG_PATH . $pathToFile);
}
return RETURN_IMG_PATH . $pathToFile;
}
示例11: write
/**
* Write a gif image to file
* @param File file of the image
* @param resource internal PHP image resource
*/
public function write(File $file, $resource)
{
$this->checkIfWriteIsPossible($file, $resource, 'gif');
imageGif($resource, $file->getAbsolutePath());
}
示例12: resizeImage
/**
* Generate images of alternate sizes.
*/
function resizeImage($cnvrt_arry)
{
global $platform, $imgs, $cnvrt_path, $reqd_image, $convert_writable, $convert_magick, $convert_GD, $convert_cmd, $cnvrt_alt, $cnvrt_mesgs, $compat_quote;
if (empty($imgs) || $convert_writable == FALSE) {
return;
}
if ($convert_GD == TRUE && !($gd_version = gdVersion())) {
return;
}
if ($cnvrt_alt['no_prof'] == TRUE) {
$strip_prof = ' +profile "*"';
} else {
$strip_prof = '';
}
if ($cnvrt_alt['mesg_on'] == TRUE) {
$str = '';
}
foreach ($imgs as $img_file) {
if ($cnvrt_alt['indiv'] == TRUE && $img_file != $reqd_image['file']) {
continue;
}
$orig_img = $reqd_image['pwd'] . '/' . $img_file;
$cnvrtd_img = $cnvrt_path . '/' . $cnvrt_arry['prefix'] . $img_file;
if (!is_file($cnvrtd_img)) {
$img_size = GetImageSize($orig_img);
$height = $img_size[1];
$width = $img_size[0];
$area = $height * $width;
$maxarea = $cnvrt_arry['maxwid'] * $cnvrt_arry['maxwid'] * 0.9;
$maxheight = $cnvrt_arry['maxwid'] * 0.75 + 1;
if ($area > $maxarea || $width > $cnvrt_arry['maxwid'] || $height > $maxheight) {
if ($width / $cnvrt_arry['maxwid'] >= $height / $maxheight) {
$dim = 'W';
}
if ($height / $maxheight >= $width / $cnvrt_arry['maxwid']) {
$dim = 'H';
}
if ($dim == 'W') {
$cnvt_percent = round(0.9375 * $cnvrt_arry['maxwid'] / $width * 100, 2);
}
if ($dim == 'H') {
$cnvt_percent = round(0.75 * $cnvrt_arry['maxwid'] / $height * 100, 2);
}
// convert it
if ($convert_magick == TRUE) {
// Image Magick image conversion
if ($platform == 'Win32' && $compat_quote == TRUE) {
$winquote = '"';
} else {
$winquote = '';
}
exec($winquote . $convert_cmd . ' -geometry ' . $cnvt_percent . '%' . ' -quality ' . $cnvrt_arry['qual'] . ' -sharpen ' . $cnvrt_arry['sharpen'] . $strip_prof . ' "' . $orig_img . '"' . ' "' . $cnvrtd_img . '"' . $winquote);
$using = $cnvrt_mesgs['using IM'];
} elseif ($convert_GD == TRUE) {
// GD image conversion
if (eregi('\\.jpg$|\\.jpeg$', $img_file) == TRUE && (imageTypes() & IMG_JPG) == TRUE) {
$src_img = imageCreateFromJpeg($orig_img);
} elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_PNG) == TRUE) {
$src_img = imageCreateFromPng($orig_img);
} elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_GIF) == TRUE) {
$src_img = imageCreateFromGif($orig_img);
} else {
continue;
}
$src_width = imageSx($src_img);
$src_height = imageSy($src_img);
$dest_width = $src_width * ($cnvt_percent / 100);
$dest_height = $src_height * ($cnvt_percent / 100);
if ($gd_version >= 2) {
$dst_img = imageCreateTruecolor($dest_width, $dest_height);
imageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
} else {
$dst_img = imageCreate($dest_width, $dest_height);
imageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
}
imageDestroy($src_img);
if (eregi('\\.jpg$|\\.jpeg$/i', $img_file) == TRUE && (imageTypes() & IMG_JPG) == TRUE) {
imageJpeg($dst_img, $cnvrtd_img, $cnvrt_arry['qual']);
} elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_PNG) == TRUE) {
imagePng($dst_img, $cnvrtd_img);
} elseif (eregi('\\.gif$/i', $img_file) == TRUE && (imageTypes() & IMG_GIF) == TRUE) {
imageGif($dst_img, $cnvrtd_img);
}
imageDestroy($dst_img);
$using = $cnvrt_mesgs['using GD'] . $gd_version;
}
if ($cnvrt_alt['mesg_on'] == TRUE && is_file($cnvrtd_img)) {
$str .= " <small>\n" . ' ' . $cnvrt_mesgs['generated'] . $cnvrt_arry['txt'] . $cnvrt_mesgs['converted'] . $cnvrt_mesgs['image_for'] . $img_file . $using . ".\n" . " </small>\n <br />\n";
}
}
}
}
if (isset($str)) {
return $str;
}
}
示例13: getTemporaryImageWithText
/**
* Creates error image based on gfx/notfound_thumb.png
* Requires GD lib enabled, otherwise it will exit with the three
* textstrings outputted as text. Outputs the image stream to browser and exits!
*
* @param string $filename Name of the file
* @param string $textline1 Text line 1
* @param string $textline2 Text line 2
* @param string $textline3 Text line 3
* @return void
* @throws \RuntimeException
*
* @internal Don't use this method from outside the LocalImageProcessor!
*/
public function getTemporaryImageWithText($filename, $textline1, $textline2, $textline3)
{
if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
throw new \RuntimeException('TYPO3 Fatal Error: No gdlib. ' . $textline1 . ' ' . $textline2 . ' ' . $textline3, 1270853952);
}
// Creates the basis for the error image
if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
$im = imagecreatefrompng(PATH_typo3 . 'gfx/notfound_thumb.png');
} else {
$im = imagecreatefromgif(PATH_typo3 . 'gfx/notfound_thumb.gif');
}
// Sets background color and print color.
$white = imageColorAllocate($im, 255, 255, 255);
$black = imageColorAllocate($im, 0, 0, 0);
// Prints the text strings with the build-in font functions of GD
$x = 0;
$font = 0;
if ($textline1) {
imagefilledrectangle($im, $x, 9, 56, 16, $white);
imageString($im, $font, $x, 9, $textline1, $black);
}
if ($textline2) {
imagefilledrectangle($im, $x, 19, 56, 26, $white);
imageString($im, $font, $x, 19, $textline2, $black);
}
if ($textline3) {
imagefilledrectangle($im, $x, 29, 56, 36, $white);
imageString($im, $font, $x, 29, substr($textline3, -14), $black);
}
// Outputting the image stream and exit
if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
imagePng($im, $filename);
} else {
imageGif($im, $filename);
}
}
示例14: image_constrain_gd
//.........这里部分代码省略.........
// Нет - просто скопируем файл
if (!copy($src_file, $dst_file)) {
return false;
}
return true;
}
// Размеры превью при пропорциональном уменьшении
@(list($dst_w, $dst_h) = $this->calc_contrain_size($src_w, $src_h, $max_w, $max_h));
// Читаем изображение
switch ($src_type) {
case 'image/jpeg':
$src_img = imageCreateFromJpeg($src_file);
break;
case 'image/gif':
$src_img = imageCreateFromGif($src_file);
break;
case 'image/png':
$src_img = imageCreateFromPng($src_file);
imagealphablending($src_img, true);
break;
default:
return false;
}
if (empty($src_img)) {
return false;
}
$src_colors = imagecolorstotal($src_img);
// create destination image (indexed, if possible)
if ($src_colors > 0 && $src_colors <= 256) {
$dst_img = imagecreate($dst_w, $dst_h);
} else {
$dst_img = imagecreatetruecolor($dst_w, $dst_h);
}
if (empty($dst_img)) {
return false;
}
$transparent_index = imagecolortransparent($src_img);
if ($transparent_index >= 0 && $transparent_index <= 128) {
$t_c = imagecolorsforindex($src_img, $transparent_index);
$transparent_index = imagecolorallocate($dst_img, $t_c['red'], $t_c['green'], $t_c['blue']);
if ($transparent_index === false) {
return false;
}
if (!imagefill($dst_img, 0, 0, $transparent_index)) {
return false;
}
imagecolortransparent($dst_img, $transparent_index);
} elseif ($src_type === 'image/png') {
if (!imagealphablending($dst_img, false)) {
return false;
}
$transparency = imagecolorallocatealpha($dst_img, 0, 0, 0, 127);
if (false === $transparency) {
return false;
}
if (!imagefill($dst_img, 0, 0, $transparency)) {
return false;
}
if (!imagesavealpha($dst_img, true)) {
return false;
}
}
// resample the image with new sizes
if (!imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h)) {
return false;
}
// Watermark
if (!empty($watermark) && is_readable($watermark)) {
$overlay = imagecreatefrompng($watermark);
// Get the size of overlay
$owidth = imagesx($overlay);
$oheight = imagesy($overlay);
$watermark_x = min(($dst_w - $owidth) * $watermark_offet_x / 100, $dst_w);
$watermark_y = min(($dst_h - $oheight) * $watermark_offet_y / 100, $dst_h);
imagecopy($dst_img, $overlay, $watermark_x, $watermark_y, 0, 0, $owidth, $oheight);
//imagecopymerge($dst_img, $overlay, $watermark_x, $watermark_y, 0, 0, $owidth, $oheight, $watermark_opacity*100);
}
// recalculate quality value for png image
if ('image/png' === $src_type) {
$quality = round($quality / 100 * 10);
if ($quality < 1) {
$quality = 1;
} elseif ($quality > 10) {
$quality = 10;
}
$quality = 10 - $quality;
}
// Сохраняем изображение
switch ($src_type) {
case 'image/jpeg':
return imageJpeg($dst_img, $dst_file, $quality);
case 'image/gif':
return imageGif($dst_img, $dst_file, $quality);
case 'image/png':
imagesavealpha($dst_img, true);
return imagePng($dst_img, $dst_file, $quality);
default:
return false;
}
}
示例15: getTemporaryImageWithText
/**
* Creates error image based on gfx/notfound_thumb.png
* Requires GD lib enabled, otherwise it will exit with the three
* textstrings outputted as text. Outputs the image stream to browser and exits!
*
* @param string $filename Name of the file
* @param string $textline1 Text line 1
* @param string $textline2 Text line 2
* @param string $textline3 Text line 3
* @return void
* @throws \RuntimeException
*/
public function getTemporaryImageWithText($filename, $textline1, $textline2, $textline3)
{
if (empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'])) {
throw new \RuntimeException('TYPO3 Fatal Error: No gdlib. ' . $textline1 . ' ' . $textline2 . ' ' . $textline3, 1270853952);
}
// Creates the basis for the error image
$basePath = ExtensionManagementUtility::extPath('core') . 'Resources/Public/Images/';
if (!empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'])) {
$im = imagecreatefrompng($basePath . 'NotFound.png');
} else {
$im = imagecreatefromgif($basePath . 'NotFound.gif');
}
// Sets background color and print color.
$white = imageColorAllocate($im, 255, 255, 255);
$black = imageColorAllocate($im, 0, 0, 0);
// Prints the text strings with the build-in font functions of GD
$x = 0;
$font = 0;
if ($textline1) {
imagefilledrectangle($im, $x, 9, 56, 16, $white);
imageString($im, $font, $x, 9, $textline1, $black);
}
if ($textline2) {
imagefilledrectangle($im, $x, 19, 56, 26, $white);
imageString($im, $font, $x, 19, $textline2, $black);
}
if ($textline3) {
imagefilledrectangle($im, $x, 29, 56, 36, $white);
imageString($im, $font, $x, 29, substr($textline3, -14), $black);
}
// Outputting the image stream and exit
if (!empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'])) {
imagePng($im, $filename);
} else {
imageGif($im, $filename);
}
}