本文整理汇总了PHP中imagecreatefromgif函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecreatefromgif函数的具体用法?PHP imagecreatefromgif怎么用?PHP imagecreatefromgif使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecreatefromgif函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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;
}
示例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());
}
示例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;
}
}
示例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;
}
}
示例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));
}
}
示例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;
}
}
示例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);
}
}
示例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");
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}