本文整理汇总了PHP中Imagegif函数的典型用法代码示例。如果您正苦于以下问题:PHP Imagegif函数的具体用法?PHP Imagegif怎么用?PHP Imagegif使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Imagegif函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createnewpicture
private function createnewpicture()
{
$local = $this->path_two . $this->file['name'];
move_uploaded_file($this->file['tmp_name'], $local);
$filename = $this->file['tmp_name'] . "/" . $this->file['name'];
$this->location = $this->path . "/" . $this->file['name'];
switch ($this->file['type']) {
case 'image/jpeg':
$src = imagecreatefromjpeg($local);
break;
case 'image/png':
$src = imagecreatefrompng($local);
break;
case 'image/gif':
$src = imagecreatefromgif($local);
break;
default:
break;
}
$sx = imagesx($src);
$sy = imagesy($src);
$new_image = imagecreatetruecolor($this->newwidth, $this->newheight);
if (imagecopyresized($new_image, $src, 0, 0, 0, 0, $this->newwidth, $this->newheight, $sx, $sy)) {
if (ImageJpeg($new_image, $this->location) || Imagegif($new_image, $this->location) || Imagepng($new_image, $this->location)) {
//imagejpeg($this->location);
return true;
}
} else {
return false;
}
}
示例2: createBarCode
public function createBarCode($image_type = 'png', $file_name = null)
{
$this->parseCode();
$this->image = ImageCreate($this->width + 2 * $this->quiet_zone, $this->height + $this->font_height + $this->quiet_zone);
$this->bgcolor = imagecolorallocate($this->image, $this->bgcolor >> 16, $this->bgcolor >> 8 & 0xff, $this->bgcolor & 0xff);
$this->color = imagecolorallocate($this->image, $this->color >> 16, $this->color >> 8 & 0xff, $this->color & 0xff);
ImageFilledRectangle($this->image, 0, 0, $this->width + 2 * $this->quiet_zone, $this->height + $this->font_height, $this->bgcolor);
$sx = $this->quiet_zone;
$sy = $this->font_height - 1;
$fw = 10;
//編號為2或3的字體的寬度為10,為4或5的字體寬度為11
if ($this->font_type > 3) {
$sy++;
$fw = 11;
}
$ex = 0;
if ($this->text) {
//不显示号码,则生成满的条码
if ($this->showType == 'top') {
$ey = $this->height + $this->font_height - 2;
//条码显示上方
} else {
if ($this->showType == 'bottom') {
$ey = $this->height - 2;
//条码显示下方
$sy = $this->quiet_zone;
}
}
} else {
$ey = $this->height + $this->font_height;
$sy = $this->quiet_zone;
}
for ($i = 0; $i < strlen($this->bin_code); $i++) {
$ex = $sx + $this->unit_width * (int) $this->bin_code[$i] - 1;
if ($i % 2 == 0) {
ImageFilledRectangle($this->image, $sx, $sy, $ex, $ey, $this->color);
}
$sx = $ex + 1;
}
if ($this->text) {
//存在条码号再显示
$t_num = strlen($this->text);
$t_x = $this->width / $t_num;
$t_sx = ($t_x - $fw) / 2;
//目的为了使文字居中平均分布
if ($this->showType == 'top') {
$y = 0;
} else {
if ($this->showType == 'bottom') {
$y = $this->height;
}
}
for ($i = 0; $i < $t_num; $i++) {
imagechar($this->image, $this->font_type, 6 * $this->unit_width + $t_sx + $i * $t_x, $y, $this->text[$i], $this->color);
}
}
if (!$file_name) {
header("Content-Type: image/" . $image_type);
}
switch ($image_type) {
case 'jpg':
case 'jpeg':
Imagejpeg($this->image, $file_name);
break;
case 'png':
Imagepng($this->image, $file_name);
break;
case 'gif':
break;
Imagegif($this->image, $file_name);
default:
Imagepng($this->image, $file_name);
break;
}
}
示例3: getCode
public function getCode()
{
Header("Content-type: image/png");
/*
* 初始化
*/
$border = 1;
//是否要边框 1要:0不要
$how = 4;
//验证码位数
$w = $how * 15;
//图片宽度
$h = 20;
//图片高度
$fontsize = 6;
//字体大小
$alpha = "abcdefghijkmnopqrstuvwxyz";
//验证码内容1:字母
$number = "023456789";
//验证码内容2:数字
$randcode = "";
//验证码字符串初始化
srand((double) microtime() * 1000000);
//初始化随机数种子
$im = ImageCreate($w, $h);
//创建验证图片
/*
* 绘制基本框架
*/
$bgcolor = ImageColorAllocate($im, 255, 255, 255);
//设置背景颜色
ImageFill($im, 0, 0, $bgcolor);
//填充背景色
if ($border) {
$black = ImageColorAllocate($im, 0, 0, 0);
//设置边框颜色
ImageRectangle($im, 0, 0, $w - 1, $h - 1, $black);
//绘制边框
}
/*
* 逐位产生随机字符
*/
for ($i = 0; $i < $how; $i++) {
$alpha_or_number = mt_rand(0, 1);
//字母还是数字
$str = $alpha_or_number ? $alpha : $number;
$which = mt_rand(0, strlen($str) - 1);
//取哪个字符
$code = substr($str, $which, 1);
//取字符
$j = !$i ? 4 : $j + 15;
//绘字符位置
$color3 = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
//字符随即颜色
ImageChar($im, $fontsize, $j, 3, $code, $color3);
//绘字符
$randcode .= $code;
//逐位加入验证码字符串
}
//把验证码字符串写入session
session_start();
$_SESSION['authnum_session'] = $randcode;
/*
* 添加干扰
*/
for ($i = 0; $i < 1; $i++) {
$color1 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
//干扰线颜色
ImageArc($im, mt_rand(-5, $w), mt_rand(-5, $h), mt_rand(20, 300), mt_rand(20, 200), 55, 44, $color1);
//干扰线
}
for ($i = 0; $i < $how * 40; $i++) {
$color2 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
//干扰点颜色
ImageSetPixel($im, mt_rand(0, $w), mt_rand(0, $h), $color2);
//干扰点
}
//关键代码,防止出现'图像因其本身有错无法显示'的问题
ob_clean();
/*绘图结束*/
Imagegif($im);
ImageDestroy($im);
/*绘图结束*/
}
示例4: fwrite
fwrite($fp, $ob_contents);
fclose($fp);
ob_end_flush();
}
}
if (substr($_GET['img'], -3) == "gif") {
header("Content-type: image/gif");
if (file_exists($path)) {
echo file_get_contents($path);
} else {
$dst_img = ImageCreate($new_w, $new_h);
$src_img = ImageCreateFromGif($_image_);
ImagePaletteCopy($dst_img, $src_img);
ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img));
ob_start();
$img = Imagegif($dst_img, '', $_quality_);
$ob_contents = ob_get_contents();
// Save file
$fp = fopen("{$path}", 'wb');
fwrite($fp, $ob_contents);
fclose($fp);
ob_end_flush();
}
}
if (substr($_GET['img'], -3) == "png") {
header("Content-type: image/png");
if (file_exists($path)) {
echo file_get_contents($path);
} else {
if (strnatcmp(phpversion(), '4.3.0') > 0) {
$_quality_ = (int) ($_quality_ / 10);
示例5: show
function show()
{
Header("Content-type: image/gif");
/*
* ��ʼ��
*/
$border = 0;
//�Ƿ�Ҫ�߿� 1Ҫ:0��Ҫ
$how = $this->num;
//��֤��λ��
$w = $this->width;
//ͼƬ���
$h = $this->height;
//ͼƬ�߶�
$fontsize = 5;
//�����С
$alpha = "abcdefghijkmnopqrstuvwxyz";
//��֤������1:��ĸ
$number = "023456789";
//��֤������2:����
$randcode = "";
//��֤���ַ�����ʼ��
srand((double) microtime() * 1000000);
//��ʼ�����������
$im = ImageCreate($w, $h);
//������֤ͼƬ
/*
* ���ƻ������
*/
$bgcolor = ImageColorAllocate($im, 255, 255, 255);
//���ñ�����ɫ
ImageFill($im, 0, 0, $bgcolor);
//��䱳��ɫ
if ($border) {
$black = ImageColorAllocate($im, 0, 0, 0);
//���ñ߿���ɫ
ImageRectangle($im, 0, 0, $w - 1, $h - 1, $black);
//���Ʊ߿�
}
/*
* ��λ��������ַ�
*/
for ($i = 0; $i < $how; $i++) {
$alpha_or_number = mt_rand(0, 1);
//��ĸ��������
$str = $alpha_or_number ? $alpha : $number;
$which = mt_rand(0, strlen($str) - 1);
//ȡ�ĸ��ַ�
$code = substr($str, $which, 1);
//ȡ�ַ�
$j = !$i ? 4 : $j + 15;
//���ַ�λ��
$color3 = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
//�ַ��漴��ɫ
ImageChar($im, $fontsize, $j, 3, $code, $color3);
//���ַ�
$randcode .= $code;
//��λ������֤���ַ���
}
/*
* ��Ӹ���
*/
for ($i = 0; $i < 5; $i++) {
$color1 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
//��������ɫ
ImageArc($im, mt_rand(-5, $w), mt_rand(-5, $h), mt_rand(20, 300), mt_rand(20, 200), 55, 44, $color1);
//������
}
for ($i = 0; $i < $how * 15; $i++) {
$color2 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
//���ŵ���ɫ
ImageSetPixel($im, mt_rand(0, $w), mt_rand(0, $h), $color2);
//���ŵ�
}
//����֤���ַ���д��session
//$this->session->set_userdata(array($this->name=>$randcode));
$_SESSION[$this->name] = $randcode;
/*��ͼ����*/
Imagegif($im);
ImageDestroy($im);
/*��ͼ����*/
}
示例6: srand
srand((double) microtime() * 1000000);
$im = ImageCreate($w, $h);
$bgcolor = ImageColorAllocate($im, 255, 255, 255);
ImageFill($im, 0, 0, $bgcolor);
if ($border) {
$black = ImageColorAllocate($im, 0, 0, 0);
ImageRectangle($im, 0, 0, $w - 1, $h - 1, $black);
}
for ($i = 0; $i < $how; $i++) {
$alpha_or_number = mt_rand(0, 1);
$str = $alpha_or_number ? $alpha : $number;
$which = mt_rand(0, strlen($str) - 1);
$code = substr($str, $which, 1);
$j = !$i ? 4 : $j + 15;
$color3 = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
ImageChar($im, $fontsize, $j, 3, $code, $color3);
$randcode .= $code;
}
for ($i = 0; $i < 5; $i++) {
$color1 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
ImageArc($im, mt_rand(-5, $w), mt_rand(-5, $h), mt_rand(20, 300), mt_rand(20, 200), 55, 44, $color1);
}
for ($i = 0; $i < $how * 40; $i++) {
$color2 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
ImageSetPixel($im, mt_rand(0, $w), mt_rand(0, $h), $color2);
}
$_SESSION['randcode'] = $randcode;
Imagegif($im);
ImageDestroy($im);
?>
示例7: show
/**
* 生产验证码
*/
function show()
{
/*
* 初始化
*/
$randcode = "";
//验证码字符串初始化
$im = ImageCreate($this->width, $this->height);
//创建验证图片
/*
* 绘制基本框架
*/
$bgcolor = ImageColorAllocate($im, 255, 255, 255);
//设置背景颜色
ImageFill($im, 0, 0, $bgcolor);
//填充背景色
if ($this->border) {
$black = ImageColorAllocate($im, 0, 0, 0);
//设置边框颜色
ImageRectangle($im, 0, 0, $w - 1, $h - 1, $black);
//绘制边框
}
/*
* 逐位产生随机字符
*/
for ($i = 0; $i < $this->num; $i++) {
$alpha_or_number = mt_rand(0, 1);
//字母还是数字
$str = $alpha_or_number ? $this->alpha : $this->number;
$which = mt_rand(0, strlen($str) - 1);
//取哪个字符
$code = substr($str, $which, 1);
//取字符
$j = !$i ? 4 : $j + 15;
//绘字符位置
$color3 = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
//字符随即颜色
imagettftext($im, $this->fontsize, 0, $j, $this->fontsize * 1.5, $color3, $this->fontpath, $code);
//绘字符
$randcode .= $code;
//逐位加入验证码字符串
}
/*
* 添加干扰
*/
for ($i = 0; $i < 5; $i++) {
$color1 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
//干扰线颜色
ImageArc($im, mt_rand(-5, $this->width), mt_rand(-5, $this->height), mt_rand(20, 300), mt_rand(20, 200), 55, 44, $color1);
//干扰线
}
for ($i = 0; $i < $this->num * 15; $i++) {
$color2 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
//干扰点颜色
ImageSetPixel($im, mt_rand(0, $this->width), mt_rand(0, $this->height), $color2);
//干扰点
}
// 保存验证码
$key = $this->authcode($this->seKey);
$code = $this->authcode(strtoupper($randcode));
$secode = array();
$secode['verify_code'] = $code;
// 把校验码保存到session
$secode['verify_time'] = $this->now;
// 验证码创建时间
$_SESSION[$key] = $secode;
/*绘图结束*/
Header("Content-type: image/gif");
Imagegif($im);
ImageDestroy($im);
/*绘图结束*/
}
示例8: imageResize
function imageResize()
{
global $engine_path, $ImageTrimX, $ImageTrimY;
$source = $this->image;
$newWidth = $this->newWidth;
$newHeight = $this->newHeight;
$imType = $this->type;
if ($imType == "jpeg" || $imType == "pjpeg") {
$srcImage = ImageCreateFromJPEG($source);
} elseif ($imType == "gif") {
$srcImage = LoadGif($source);
} else {
$srcImage = ImageCreateFromPNG($source);
}
$srcWidth = ImageSX($srcImage);
$srcHeight = ImageSY($srcImage);
$ratioWidth = $srcWidth / $newWidth;
$ratioHeight = $srcHeight / $newHeight;
if ($ratioWidth < 1 && $this->fix == "width" || $ratioHeight < 1 && $this->fix == "height") {
$destWidth = $srcWidth;
$destHeight = $srcHeight;
//print "mode 1";
//exit;
} elseif ($ratioWidth > $ratioHeight || $ratioWidth < $ratioHeight && $this->fix != "width" || $this->fix == "height") {
$destWidth = $srcWidth / $ratioHeight;
$destHeight = $newHeight;
//print "mode 2";
//exit;
} else {
$destWidth = $newWidth;
$destHeight = $srcHeight / $ratioWidth;
//print "mode 3 $ratioHeight $ratioWidth $this->fix";
//exit;
}
//$this->newWidth=$destWidth;
//$this->newHeight=$desHeight;
//print "$this->newWidth - $this->newHeight";
//print $srcImage." $ratioWidth $ratioHeight $this->fix $destWidth $destHeight";
//print "-($newHeight-$destHeight)/2";
//exit;
if ($newWidth != $srcWidth && $newHeight != $srcHeight && $newWidth != 160) {
if (!strlen($ImageTrim)) {
$ImageTrim = 2;
}
if ($ImageTrimY == 0) {
$y = 0;
} elseif ($ImageTrimY == 1) {
$y = ($newHeight - $destHeight) / 4;
} elseif ($ImageTrimY == 2) {
$y = ($newHeight - $destHeight) / 2;
} elseif ($ImageTrimY == 3) {
$y = 3 * ($newHeight - $destHeight) / 2;
} elseif ($ImageTrimY == 4) {
$y = 5 * ($newHeight - $destHeight) / 2;
}
if ($ImageTrimX == 0) {
$x = 0;
} elseif ($ImageTrimX == 1) {
$x = ($newWidth - $destWidth) / 4;
} elseif ($ImageTrimX == 2) {
$x = ($newWidth - $destWidth) / 2;
} elseif ($ImageTrimX == 3) {
$x = 3 * ($newWidth - $destWidth) / 2;
} elseif ($ImageTrimX == 4) {
$x = 5 * ($newWidth - $destWidth) / 2;
}
//print "$ImageTrimY $ImageTrimX $x $y";
//exit;
$destImage = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($destImage, $srcImage, $x, $y, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
} else {
$destImage = imagecreatetruecolor($destWidth, $destHeight);
imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
}
if ($this->mix) {
$destImage = $this->mix($destImage);
}
$name = $engine_path . "img/small/" . $this->name;
if ($imType == "jpeg" || $imType == "pjpeg") {
Imagejpeg($destImage, $name);
} elseif ($imType == "gif") {
Imagegif($destImage, $name);
} else {
Imagepng($destImage, $name);
}
$file['tmp_name'] = $name;
ImageDestroy($srcImage);
ImageDestroy($destImage);
return $file;
}
示例9: resizeImage
function resizeImage($originalImage, $newImage, $newWidth, $newHeight, $bgred = 0xff, $bggreen = 0xff, $bgblue = 0xff, $interlace = 1, $jpegquality = 75)
{
//abre imagem original
switch ($imageType = exif_imagetype($originalImage)) {
case IMAGETYPE_GIF:
if (imagetypes() & IMG_GIF) {
$imOriginal = @imagecreatefromgif($originalImage);
} else {
die('<P>Formato de imagem não suportado pelo PHP: ' . $imageType . ' ' . image_type_to_mime_type($imageType) . '.</P>');
}
break;
case IMAGETYPE_JPEG:
if (imagetypes() & IMG_JPG) {
$imOriginal = @imagecreatefromjpeg($originalImage);
} else {
die('<P>Formato de imagem não suportado pelo PHP: ' . $imageType . ' ' . image_type_to_mime_type($imageType) . '.</P>');
}
break;
case IMAGETYPE_PNG:
if (imagetypes() & IMG_PNG) {
$imOriginal = @imagecreatefrompng($originalImage);
} else {
die('<P>Formato de imagem não suportado pelo PHP: ' . $imageType . ' ' . image_type_to_mime_type($imageType) . '.</P>');
}
break;
default:
die('<P>Formato de imagem não reconhecido pelo algoritmo: ' . $imageType . ' ' . image_type_to_mime_type($imageType) . '.</P>');
}
if (!$imOriginal) {
return false;
}
//cria a imagem nova
$imThumb = @imagecreatetruecolor($newWidth, $newHeight);
if (!$imThumb) {
return false;
}
imagefilledrectangle($imThumb, 0, 0, $newWidth, $newHeight, imagecolorallocate($imThumb, $bgred, $bggreen, $bgblue));
//cuida do aspect ratio
$xOrig = imagesx($imOriginal);
$yOrig = imagesy($imOriginal);
$xThumb = $newWidth;
$yThumb = $newHeight;
$ratioOrig = $xOrig / $yOrig;
$ratioThumb = $xThumb / $yThumb;
if ($ratioOrig > $ratioThumb) {
$yThumb = round($xThumb / $ratioOrig);
} elseif ($ratioOrig < $ratioThumb) {
$xThumb = round($yThumb * $ratioOrig);
}
$xMargin = round(($newWidth - $xThumb) / 2);
$yMargin = round(($newHeight - $yThumb) / 2);
//modifica o tamanho
imagecopyresampled($imThumb, $imOriginal, $xMargin, $yMargin, 0, 0, $xThumb, $yThumb, $xOrig, $yOrig);
ImageDestroy($imOriginal);
//entrelaça, se necessário
if ($interlace) {
imageinterlace($imThumb, $interlace);
}
//salva a imagem
if (!$newImage) {
Header('Content-type: ' . image_type_to_mime_type($imageType));
}
switch ($imageType) {
case IMAGETYPE_GIF:
Imagegif($imThumb, $newImage);
break;
case IMAGETYPE_JPEG:
Imagejpeg($imThumb, $newImage, $jpegquality);
break;
case IMAGETYPE_PNG:
if ($newImage) {
Imagepng($imThumb, $newImage);
} else {
Imagepng($imThumb);
}
break;
}
ImageDestroy($imThumb);
return true;
}
示例10: imagecreate
<?php
// erstmal ein neues leeres Bild erstellen (breite, höhe)
$buchbild = imagecreate(140, 180);
// ne Hintergrundfarbe erstellen, die später zur Transparenz genutzt wird
// (am Besten ne Farbe, die selten in Bildern verwendet wird)
$hintergrundfarbe = imagecolorallocate($buchbild, 255, 0, 255);
// eine Grafik erstellen von nem vorhandenen Bild (buch2.gif muss da sein)
$buchgrafik = ImageCreateFromGIF("buch2.gif");
// diese Grafik in unser Bild kopieren
// Imagecopy(zielgrafik, quellgrafik, zielX, zielY, quelleX, quelleY, quB, quH)
Imagecopy($buchbild, $buchgrafik, 0, 0, 0, 0, 140, 180);
// eine Textfarbe erstellen
$textfarbe = imagecolorallocate($buchbild, 0, 0, 0);
// einen Text ALS BILD erstellen
// ImageString(zielgrafik,schrift,X,Y,text,textfarbe)
ImageString($buchbild, 5, 23, 50, "mein Text", $textfarbe);
ImageString($buchbild, 2, 23, 65, "noch einer", $textfarbe);
ImageString($buchbild, 1, 23, 100, "von: mir", $textfarbe);
// nun unser (evtl. vorher schon transparentes) GIF transparent machen
// imagecolortransparent(grafik, farbe)
imagecolortransparent($buchbild, $hintergrundfarbe);
// und abspeichern (Imagegif(bild, zielort, qualität))
Imagegif($buchbild, "erstelltesBild.gif", 100);
?>
<img src="erstelltesBild.gif">
</body>
</html>
示例11: _output_image
function _output_image($destination_file, $image_type, $image)
{
//if destination file is empty image will be output to browser
// right now $image_type can be JPEG or PNG
global $ERR, $create_text;
$destination_file = trim($destination_file);
$res = false;
//Create Text
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$red = ImageColorAllocate($image, 255, 0, 0);
$blue = ImageColorAllocate($image, 0, 0, 255);
$lightblue = ImageColorAllocate($image, 0, 128, 255);
$green = ImageColorAllocate($image, 0, 255, 0);
$violet = ImageColorAllocate($image, 225, 128, 225);
$orange = ImageColorAllocate($image, 255, 128, 0);
$gray = ImageColorAllocate($image, 192, 192, 192);
$pink = ImageColorAllocate($image, 255, 0, 128);
$brown = ImageColorAllocate($image, 128, 0, 0);
$darkgreen = ImageColorAllocate($image, 0, 128, 0);
ImageString($image, 3, 2, 1, $create_text, $white);
if ($image) {
switch ($image_type) {
case 'JPEG':
case 'JPG':
$res = ImageJpeg($image, $destination_file, $this->jpeg_quality);
break;
case 'PNG':
$res = Imagepng($image, $destination_file);
break;
case 'GIF':
$res = Imagegif($image, $destination_file);
break;
default:
$this->error($ERR["UNKNOWN_OUTPUT_FORMAT"] . " {$image_type}");
break;
}
} else {
$this->error($ERR["NO_IMAGE_FOR_OUTPUT"]);
}
if (!$res) {
$this->error($ERR["UNABLE_TO_OUTPUT"] . " {$destination_file}");
}
return $res;
}
示例12: overlay
function overlay($backpic, $overpic, $x, $y, $w, $h)
{
$backsize = getimagesize($backpic);
$oversize = getimagesize($overpic);
if ($backsize[2] == 1) {
$dstimg = ImageCreateFromGIF($backpic);
} elseif ($backsize[2] == 2) {
$dstimg = ImageCreateFromJPEG($backpic);
} elseif ($backsize[2] == 3) {
$dstimg = ImageCreateFromPNG($backpic);
}
if ($oversize[2] == 1) {
$srcimg = ImageCreateFromGIF($overpic);
} elseif ($oversize[2] == 2) {
$srcimg = ImageCreateFromJPEG($overpic);
} elseif ($oversize[2] == 3) {
$srcimg = ImageCreateFromPNG($overpic);
}
Imagecopymerge($dstimg, $srcimg, $x, $y, 0, 0, $w, $h, 100);
if ($backsize[2] == 1) {
Imagegif($dstimg, $backpic, 100);
} elseif ($backsize[2] == 2) {
Imagejpeg($dstimg, $backpic, 100);
} elseif ($backsize[2] == 3) {
Imagepng($dstimg, $backpic, 0);
}
@ImageDestroy($dstimg);
@ImageDestroy($srcimg);
}
示例13: gdfillcolor
function gdfillcolor($srcFile, $dstFile, $dstW, $dstH)
{
@ImageAlphaBlending($srcFile, true);
$picdata = GetImageSize($srcFile);
switch ($picdata[2]) {
case 1:
$im = @ImageCreateFromGIF($srcFile);
break;
case 2:
$im = @imageCreateFromJpeg($srcFile);
break;
case 3:
$im = @ImageCreateFromPNG($srcFile);
break;
case 6:
$im = @ImageCreateFromWbmp($srcFile);
break;
}
$srcW = ImageSX($im);
$srcH = ImageSY($im);
$dstX = 0;
$dstY = 0;
if ($srcW * $dstH > $srcH * $dstW) {
$fdstH = round($srcH * $dstW / $srcW);
$dstY = floor(($dstH - $fdstH) / 2);
$fdstW = $dstW;
} else {
$fdstW = round($srcW * $dstH / $srcH);
$dstX = floor(($dstW - $fdstW) / 2);
$fdstH = $dstH;
}
$dstX = $dstX < 0 ? 0 : $dstX;
$dstY = $dstX < 0 ? 0 : $dstY;
$dstX = $dstX > $dstW / 2 ? floor($dstW / 2) : $dstX;
$dstY = $dstY > $dstH / 2 ? floor($dstH / s) : $dstY;
$ni = imagecreatetruecolor($dstW, $dstH);
$black = ImageColorAllocate($ni, 255, 255, 255);
$white = ImageColorAllocate($ni, 255, 255, 255);
imagefilledrectangle($ni, 0, 0, $dstW, $dstH, $black);
// 填充剩余背景色
if (function_exists("imagecopyresampled")) {
// 改变图片大小
imagecopyresampled($ni, $im, $dstX, $dstY, 0, 0, $fdstW, $fdstH, $srcW, $srcH);
} else {
imagecopyresized($ni, $im, $dstX, $dstY, 0, 0, $fdstW, $fdstH, $srcW, $srcH);
}
if (function_exists("Imagegif")) {
Imagegif($ni, $dstFile);
// 输出到文件
} else {
ImageJpeg($ni, $dstFile);
}
imagedestroy($im);
// 清理内存
imagedestroy($ni);
}
示例14: uploadimg
function uploadimg($filename, $width, $get_height, $path)
{
if (trim($_FILES["image"]["tmp_name"]) != "") {
$tmp_images = $_FILES["image"]["tmp_name"];
// type select
if ($_FILES['image']['type'] == 'image/jpeg' or $_FILES['image']['type'] == 'image/jpg' or $_FILES['image']['type'] == 'image/pjpeg') {
$images = $filename . ".jpg";
//upload source image
$size = getimagesize($tmp_images);
//check radio widht and height
$height = round($width * $size[1] / $size[0]);
if ($height > $get_height) {
$width = round($get_height * $size[0] / $size[1]);
$height = $get_height;
}
$images_orig = ImageCreateFromJPEG($tmp_images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
ImageJPEG($images_fin, $path . $images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
return $filename . ".jpg";
} elseif ($_FILES['image']['type'] == 'image/x-png' or $_FILES['image']['type'] == 'image/png') {
$images = $filename . ".png";
$size = getimagesize($tmp_images);
//check radio widht and height
$height = round($width * $size[1] / $size[0]);
if ($height > $get_height) {
$width = round($get_height * $size[0] / $size[1]);
$height = $get_height;
}
$images_orig = ImageCreateFromPNG($tmp_images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
Imagepng($images_fin, $path . $images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
return $filename . ".png";
} elseif ($_FILES['image']['type'] == 'image/gif') {
$images = $filename . ".gif";
$size = getimagesize($tmp_images);
//check radio widht and height
$height = round($width * $size[1] / $size[0]);
if ($height > $get_height) {
$width = round($get_height * $size[0] / $size[1]);
$height = $get_height;
}
$images_orig = ImageCreateFromgif($tmp_images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
Imagegif($images_fin, $path . $images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
return $filename . ".gif";
} else {
return FALSE;
}
}
}
示例15: imagecreatefrompng
break;
case 'image/png':
$src = imagecreatefrompng($local);
break;
case 'image/gif':
$src = imagecreatefromgif($local);
break;
default:
break;
}
$sx = imagesx($src);
//获取原图的宽
$sy = imagesy($src);
//获取原图的高
$new_image = imagecreatetruecolor($width, $height);
//用刚才给定的长和宽建立一张白的缩略图。
imagecopyresized($new_image, $src, 0, 0, 0, 0, $width, $height, $sx, $sy);
//把原图压到这张白图里头
if (Imagejpeg($new_image, $localtion) || Imagegif($new_image, $localtion) || Imagepng($new_image, $localtion)) {
//转移缩略图
echo "制作完成";
echo "<img src='{$localtion}' mce_src='{$localtion}'>";
//将缩略图显示
}
} else {
echo " <script> alert('验证码输入错误');history.back()</script>";
}
}
} else {
echo "不存在";
}