本文整理汇总了PHP中imagecreatefromgif函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecreatefromgif函数的具体用法?PHP imagecreatefromgif怎么用?PHP imagecreatefromgif使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecreatefromgif函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: load
static function load($filename)
{
$info = getimagesize($filename);
list($width, $height) = $info;
if (!$width || !$height) {
return null;
}
$image = null;
switch ($info['mime']) {
case 'image/gif':
$image = imagecreatefromgif($filename);
break;
case 'image/jpeg':
$image = imagecreatefromjpeg($filename);
break;
case 'image/png':
$image = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $white);
$png = imagecreatefrompng($filename);
imagealphablending($png, true);
imagesavealpha($png, true);
imagecopy($image, $png, 0, 0, 0, 0, $width, $height);
imagedestroy($png);
break;
}
if ($image) {
return new image($image, $width, $height);
} else {
return null;
}
}
开发者ID:nyan-cat,项目名称:easyweb,代码行数:32,代码来源:image.php
示例2: convertImage
function convertImage($originalImage, $outputImage, $quality = 100)
{
$myfile = fopen($outputImage, "w");
// jpg, png, gif or bmp?
$exploded = explode('.', $originalImage);
$ext = $exploded[count($exploded) - 1];
if (preg_match('/jpg|jpeg/i', $ext)) {
$imageTmp = imagecreatefromjpeg($originalImage);
} else {
if (preg_match('/png/i', $ext)) {
$imageTmp = imagecreatefrompng($originalImage);
} else {
if (preg_match('/gif/i', $ext)) {
$imageTmp = imagecreatefromgif($originalImage);
} else {
if (preg_match('/bmp/i', $ext)) {
$imageTmp = imagecreatefrombmp($originalImage);
} else {
return 0;
}
}
}
}
imagejpeg($imageTmp, $outputImage, $quality);
imagedestroy($imageTmp);
return $outputImage;
}
开发者ID:princeraju,项目名称:compare_images,代码行数:27,代码来源:check_similar.php
示例3: __construct
/**
* Loads image source and its properties to the instanciated object
*
* @param string $filename
* @return ImageResize
* @throws \Exception
*/
public function __construct($filename)
{
$image_info = @getimagesize($filename);
if (!$image_info) {
throw new \Exception('Could not read file');
}
list($this->original_w, $this->original_h, $this->source_type) = $image_info;
switch ($this->source_type) {
case IMAGETYPE_GIF:
$this->source_image = imagecreatefromgif($filename);
break;
case IMAGETYPE_JPEG:
$this->source_image = $this->imageCreateJpegfromExif($filename);
// set new width and height for image, maybe it has changed
$this->original_w = ImageSX($this->source_image);
$this->original_h = ImageSY($this->source_image);
break;
case IMAGETYPE_PNG:
$this->source_image = imagecreatefrompng($filename);
break;
default:
throw new \Exception('Unsupported image type');
break;
}
return $this->resize($this->getSourceWidth(), $this->getSourceHeight());
}
开发者ID:saschanos,项目名称:php-image-resize,代码行数:33,代码来源:ImageResize.php
示例4: Imagem
/**
* MÉTODO CONSTRUTOR
*
* @author Gibran
*/
function Imagem($arquivo)
{
if (is_file($arquivo)) {
$this->Arquivo = $arquivo;
// OBTÉM OS DADOS DA IMAGEM
$this->ColecaoDados = getimagesize($this->Arquivo);
// CARREGA A IMAGEM DE ACORDO COM O TIPO
switch ($this->ColecaoDados[2]) {
case 1:
$this->Recurso = imagecreatefromgif($this->Arquivo);
$this->Tipo = "image/gif";
break;
case 2:
$this->Recurso = imagecreatefromjpeg($this->Arquivo);
$this->Tipo = "image/jpeg";
imageinterlace($this->Recurso, true);
break;
case 3:
$this->Recurso = imagecreatefrompng($this->Arquivo);
$this->Tipo = "image/png";
imagealphablending($this->Recurso, false);
imagesavealpha($this->Recurso, true);
break;
default:
$this->ColecaoDados = null;
$this->Recurso = null;
$this->Tipo = null;
return null;
break;
}
} else {
return null;
}
}
开发者ID:BGCX067,项目名称:f1n4l-pr0j3c7-f0r-t3h-0n35-wh0-n33d-17-svn-to-git,代码行数:39,代码来源:Imagem.php
示例5: mkthumb
function mkthumb($img_src, $img_width = "100", $img_height = "100", $folder_scr = "include/files", $des_src = "include/files")
{
// Größe und Typ ermitteln
list($src_width, $src_height, $src_typ) = getimagesize($folder_scr . "/" . $img_src);
if (!$src_typ) {
return false;
}
// calculate new size
if ($src_width >= $src_height) {
$new_image_height = $src_height / $src_width * $img_width;
$new_image_width = $img_width;
if ($new_image_height > $img_height) {
$new_image_width = $new_image_width / $new_image_height * $img_height;
$new_image_height = $img_height;
}
} else {
$new_image_width = $src_width / $src_height * $img_height;
$new_image_height = $img_height;
if ($new_image_width > $img_width) {
$new_image_height = $new_image_height / $new_image_width * $img_width;
$new_image_width = $img_width;
}
}
// for the case that the thumbnail would be bigger then the original picture
if ($new_image_height > $src_height) {
$new_image_width = $new_image_width * $src_height / $new_image_height;
$new_image_height = $src_height;
}
if ($new_image_width > $src_width) {
$new_image_height = $new_image_height * $new_image_width / $src_width;
$new_image_width = $src_width;
}
if ($src_typ == 1) {
$image = imagecreatefromgif($folder_scr . "/" . $img_src);
$new_image = imagecreate($new_image_width, $new_image_height);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
imagegif($new_image, $des_src . "/" . $img_src . "_thumb", 100);
imagedestroy($image);
imagedestroy($new_image);
return true;
} elseif ($src_typ == 2) {
$image = imagecreatefromjpeg($folder_scr . "/" . $img_src);
$new_image = imagecreatetruecolor($new_image_width, $new_image_height);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
imagejpeg($new_image, $des_src . "/" . $img_src . "_thumb", 100);
imagedestroy($image);
imagedestroy($new_image);
return true;
} elseif ($src_typ == 3) {
$image = imagecreatefrompng($folder_scr . "/" . $img_src);
$new_image = imagecreatetruecolor($new_image_width, $new_image_height);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
imagepng($new_image, $des_src . "/" . $img_src . "_thumb");
imagedestroy($image);
imagedestroy($new_image);
return true;
} else {
return false;
}
}
开发者ID:GoeGaming,项目名称:bans.sevenelevenclan.org,代码行数:60,代码来源:thumbs.inc.php
示例6: __construct
/**
* @param string $fileName
* @param array $options
* @param array $plugins
*/
public function __construct($fileName, $options = array(), array $plugins = array())
{
parent::__construct($fileName, $options, $plugins);
$this->determineFormat();
$this->verifyFormatCompatiblity();
switch ($this->format) {
case 'GIF':
$this->oldImage = @imagecreatefromgif($this->fileName);
break;
case 'JPG':
$this->oldImage = @imagecreatefromjpeg($this->fileName);
break;
case 'PNG':
$this->oldImage = @imagecreatefrompng($this->fileName);
break;
case 'STRING':
$this->oldImage = @imagecreatefromstring($this->fileName);
break;
}
if (!is_resource($this->oldImage)) {
throw new \Exception('Invalid image file');
} else {
$this->currentDimensions = array('width' => imagesx($this->oldImage), 'height' => imagesy($this->oldImage));
}
}
开发者ID:sacredwebsite,项目名称:rainloop-webmail,代码行数:30,代码来源:GD.php
示例7: 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;
}
}
开发者ID:JiaJia01,项目名称:homework_09,代码行数:31,代码来源:picture.php
示例8: resizewidth
static function resizewidth($width, $imageold, $imagenew)
{
$image_info = getimagesize($imageold);
$image_type = $image_info[2];
if ($image_type == IMAGETYPE_JPEG) {
$image = imagecreatefromjpeg($imageold);
} elseif ($this->image_type == IMAGETYPE_GIF) {
$image = imagecreatefromgif($imageold);
} elseif ($this->image_type == IMAGETYPE_PNG) {
$image = imagecreatefrompng($imageold);
}
$ratio = imagesy($image) / imagesx($image);
$height = $width * $ratio;
//$width = imagesx($image) * $width/100;
// $height = imagesx($image) * $width/100;
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $image_info[0], $image_info[1]);
$image = $new_image;
$compression = 75;
$permissions = null;
if ($image_type == IMAGETYPE_JPEG) {
imagejpeg($image, $imagenew, $compression);
} elseif ($image_type == IMAGETYPE_GIF) {
imagegif($image, $imagenew);
} elseif ($image_type == IMAGETYPE_PNG) {
imagepng($image, $imagenew);
}
if ($permissions != null) {
chmod($imagenew, $permissions);
}
}
开发者ID:blackorwhite1233,项目名称:fakekinhdoanh,代码行数:31,代码来源:SimpleImage.php
示例9: create_thumbnail
function create_thumbnail($filename)
{
$percent = 0.1;
list($width, $height) = getimagesize("/var/www/amberandbrice.com/workspace/images/" . $filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$ext = pathinfo($filename)['extension'];
echo "<h1>{$ext}</h1>";
switch ($ext) {
case 'jpg':
case 'jpeg':
case 'JPG':
$source = imagecreatefromjpeg("images/" . $filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, "./thumbs/" . $filename);
break;
case 'gif':
$source = imagecreatefromgif("images/" . $filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, "./thumbs/" . $filename);
break;
case 'png':
$source = imagecreatefrompng("images/" . $filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, "./thumbs/" . $filename);
break;
default:
die("image extension cannot be determined");
}
}
开发者ID:bbathel12,项目名称:workspace,代码行数:31,代码来源:config.php
示例10: getLogo
public function getLogo()
{
$f_info = pathinfo($this->url_logo);
$get_w = $this->input->get('w');
$get_h = $this->input->get('h');
// Get new sizes
list($width, $height) = getimagesize($this->url_logo);
$newwidth = $get_w === FALSE ? $this->size_x : $get_w;
$newheight = $get_h === FALSE ? $this->size_y : $get_h;
$thumb = imagecreatetruecolor($newwidth, $newheight);
//compress picture size
if (strtolower($f_info['extension']) == 'jpg') {
$image = imagecreatefromjpeg($this->url_logo);
$call = 'imagejpeg';
$content = 'image/jpeg';
}
if (strtolower($f_info['extension']) == 'png') {
$image = imagecreatefrompng($this->url_logo);
$call = 'imagepng';
$content = 'image/jpeg';
}
if (strtolower($f_info['extension']) == 'gif') {
$image = imagecreatefromgif($this->url_logo);
$call = 'imagegif';
$content = 'image/gif';
}
@header('Content-Type : ' . $content);
imagecopyresized($thumb, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
call_user_func($call, $thumb);
imagedestroy($thumb);
}
开发者ID:gkawin,项目名称:siteminder,代码行数:31,代码来源:welcome.php
示例11: open
public function open($file)
{
$this->close();
// *** Get extension
$extension = strtolower(strrchr($file, '.'));
switch ($extension) {
case '.jpg':
case '.jpeg':
$this->image = @imagecreatefromjpeg($file);
break;
case '.gif':
$this->image = @imagecreatefromgif($file);
break;
case '.png':
$this->image = @imagecreatefrompng($file);
break;
default:
$this->image = FALSE;
break;
}
if ($this->image !== FALSE) {
// *** Get width and height
$this->width = imagesx($this->image);
$this->height = imagesy($this->image);
}
return $this->image;
}
开发者ID:atomicon,项目名称:atomicon-gallery,代码行数:27,代码来源:atomicon-gallery-image.php
示例12: getImage
protected function getImage($image_url)
{
$this->url = $image_url;
$mime = image_type_to_mime_type(exif_imagetype($image_url));
$im;
//Get image based on mime and set to $im
switch ($mime) {
case 'image/jpeg':
$im = imagecreatefromjpeg($image_url);
break;
case 'image/gif':
$im = imagecreatefromgif($image_url);
break;
case 'image/png':
$im = imagecreatefrompng($image_url);
break;
case 'image/wbmp':
$im = imagecreatefromwbmp($image_url);
break;
default:
return NULL;
break;
}
$this->image = $im;
return $this;
}
开发者ID:aaronbullard,项目名称:litmus,代码行数:26,代码来源:RemoteImage.php
示例13: resizeThumbnailImage
function resizeThumbnailImage($thumb, $image, $width, $height, $start_width, $start_height, $scale)
{
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
$ext = strtolower(substr(basename($image), strrpos(basename($image), '.') + 1));
$source = '';
if ($ext == 'png') {
$source = imagecreatefrompng($image);
} elseif ($ext == 'jpg' || $ext == 'jpeg') {
$source = imagecreatefromjpeg($image);
} elseif ($ext == 'gif') {
$source = imagecreatefromgif($image);
}
imagecopyresampled($newImage, $source, 0, 0, $start_width, $start_height, $newImageWidth, $newImageHeight, $width, $height);
$ext = strtolower(substr(basename($thumb), strrpos(basename($thumb), '.') + 1));
if ($ext == 'png') {
$result = imagepng($newImage, $thumb, 0);
} elseif ($ext == 'jpg' || $ext == 'jpeg') {
$result = imagejpeg($newImage, $thumb, 90);
} elseif ($ext == 'gif') {
$result = imagegif($newImage, $thumb);
}
if (!$result) {
return false;
}
chmod($thumb, 0664);
return $thumb;
}
开发者ID:roboshed,项目名称:Zuluru,代码行数:29,代码来源:image_crop.php
示例14: load
public function load($path, $extension = null, $content = null)
{
global $F;
$this->destroy();
$this->path = $path;
if (is_null($extension)) {
$extension = File::extension($path);
}
switch ($extension) {
default:
case "jpg":
$this->resourceID = @imagecreatefromjpeg($path);
break;
case "gif":
$this->resourceID = @imagecreatefromgif($path);
break;
case "png":
$this->resourceID = @imagecreatefrompng($path);
imagesavealpha($this->resourceID, true);
break;
case Image::DATA:
$this->resourceID = @imagecreatefromstring($content);
break;
}
if ($this->resourceID) {
$this->width = imagesx($this->resourceID);
$this->height = imagesy($this->resourceID);
return true;
} else {
return false;
}
}
开发者ID:jura-php,项目名称:jura,代码行数:32,代码来源:Image.php
示例15: create_from
public static function create_from($filename)
{
$size = @getimagesize($filename);
if (FALSE == $size) {
return NULL;
}
list($w, $h, $type) = $size;
$obj = new self();
switch ($type) {
// 1 = GIF,2 = JPG,3 = PNG ...
case 1:
// gif
$obj->im = imagecreatefromgif($filename);
break;
case 2:
// jpg
$obj->im = imagecreatefromjpeg($filename);
break;
case 3:
// png
$obj->im = imagecreatefrompng($filename);
break;
default:
$obj->im = FALSE;
break;
}
if (FALSE == $obj->im) {
return NULL;
}
return $obj;
}
开发者ID:xtlxs1976,项目名称:zhsdk,代码行数:31,代码来源:Image.class.php
示例16: upload
function upload($tmp, $name, $nome, $larguraP, $pasta)
{
$ext = strtolower(end(explode('.', $name)));
if ($ext == 'jpg') {
$img = imagecreatefromjpeg($tmp);
} elseif ($ext == 'gif') {
$img = imagecreatefromgif($tmp);
} else {
$img = imagecreatefrompng($tmp);
}
$x = imagesx($img);
$y = imagesy($img);
$largura = $x > $larguraP ? $larguraP : $x;
$altura = $largura * $y / $x;
if ($altura > $larguraP) {
$altura = $larguraP;
$largura = $altura * $x / $y;
}
$nova = imagecreatetruecolor($largura, $altura);
imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura, $altura, $x, $y);
imagejpeg($nova, "{$pasta}/{$nome}");
imagedestroy($img);
imagedestroy($nova);
return $nome;
}
开发者ID:mauriliovilela,项目名称:ser-social,代码行数:25,代码来源:funcoes.php
示例17: load
/**
* Load an image
*
* @param $filename
* @return Image
* @throws Exception
*/
public static function load($filename)
{
$instance = new self();
// Require GD library
if (!extension_loaded('gd')) {
throw new Exception('Required extension GD is not loaded.');
}
$instance->filename = $filename;
$info = getimagesize($instance->filename);
switch ($info['mime']) {
case 'image/gif':
$instance->image = imagecreatefromgif($instance->filename);
break;
case 'image/jpeg':
$instance->image = imagecreatefromjpeg($instance->filename);
break;
case 'image/png':
$instance->image = imagecreatefrompng($instance->filename);
imagesavealpha($instance->image, true);
imagealphablending($instance->image, true);
break;
default:
throw new Exception('Invalid image: ' . $instance->filename);
break;
}
$instance->original_info = array('width' => $info[0], 'height' => $info[1], 'orientation' => $instance->get_orientation(), 'exif' => function_exists('exif_read_data') ? $instance->exif = @exif_read_data($instance->filename) : null, 'format' => preg_replace('/^image\\//', '', $info['mime']), 'mime' => $info['mime']);
$instance->width = $info[0];
$instance->height = $info[1];
imagesavealpha($instance->image, true);
imagealphablending($instance->image, true);
return $instance;
}
开发者ID:SerdarSanri,项目名称:arx-core,代码行数:39,代码来源:Image.php
示例18: setImage
/**
* Set the image variable by using image create
*
* @param string $filename - The image filename
*/
private function setImage($filename)
{
$size = getimagesize($filename);
$this->ext = $size['mime'];
switch ($this->ext) {
// Image is a JPG
case 'image/jpg':
case 'image/jpeg':
// create a jpeg extension
$this->image = imagecreatefromjpeg($filename);
break;
// Image is a GIF
// Image is a GIF
case 'image/gif':
$this->image = @imagecreatefromgif($filename);
break;
// Image is a PNG
// Image is a PNG
case 'image/png':
$this->image = @imagecreatefrompng($filename);
break;
// Mime type not found
// Mime type not found
default:
throw new Exception("File is not an image, please use another file type.", 1);
}
$this->origWidth = imagesx($this->image);
$this->origHeight = imagesy($this->image);
}
开发者ID:swarajjena,项目名称:hackathon,代码行数:34,代码来源:Resize_image.php
示例19: image
public static function image($item, $path, $filename)
{
$image_tempname1 = $_FILES[$item]['name'];
$ImageName = $path . $image_tempname1;
$newfilename = $path . $filename;
if (move_uploaded_file($_FILES[$item]['tmp_name'], $ImageName)) {
list($width, $height, $type, $attr) = getimagesize($ImageName);
if ($type == 2) {
rename($ImageName, $newfilename);
} else {
if ($type == 1) {
$image_old = imagecreatefromgif($ImageName);
} elseif ($type == 3) {
$image_old = imagecreatefrompng($ImageName);
}
$image_jpg = imagecreatetruecolor($width, $height);
imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height);
imagejpeg($image_jpg, $newfilename);
imagedestroy($image_old);
imagedestroy($image_jpg);
}
return 1;
} else {
return 0;
}
}
开发者ID:mkrdip,项目名称:Management-Information-System,代码行数:26,代码来源:Input.php
示例20: create_pic
function create_pic($upfile, $new_path, $width)
{
$quality = 100;
$image_path = $upfile;
$image_info = getimagesize($image_path);
$exname = '';
//1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF
switch ($image_info[2]) {
case 1:
@($image = imagecreatefromgif($image_path));
$exname = 'gif';
break;
case 2:
@($image = imagecreatefromjpeg($image_path));
$exname = 'jpg';
break;
case 3:
@($image = imagecreatefrompng($image_path));
$exname = 'png';
break;
case 6:
@($image = imagecreatefromwbmp($image_path));
$exname = 'wbmp';
break;
}
$T_width = $image_info[0];
$T_height = $image_info[1];
if (!empty($image)) {
$image_x = imagesx($image);
$image_y = imagesy($image);
} else {
return FALSE;
}
@chmod($new_path, 0777);
if ($image_x > $width) {
$x = $width;
$y = intval($x * $image_y / $image_x);
} else {
@copy($image_path, $new_path . '.' . $exname);
return $exname;
}
$newimage = imagecreatetruecolor($x, $y);
imagecopyresampled($newimage, $image, 0, 0, 0, 0, $x, $y, $image_x, $image_y);
switch ($image_info[2]) {
case 1:
imagegif($newimage, $new_path . '.gif', $quality);
break;
case 2:
imagejpeg($newimage, $new_path . '.jpg', $quality);
break;
case 3:
imagepng($newimage, $new_path . '.png', $quality);
break;
case 6:
imagewbmp($newimage, $new_path . '.wbmp', $quality);
break;
}
imagedestroy($newimage);
return $exname;
}
开发者ID:yunsite,项目名称:cyaskuc,代码行数:60,代码来源:global.func.php
注:本文中的imagecreatefromgif函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论