本文整理汇总了PHP中ImageCreateFromGif函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageCreateFromGif函数的具体用法?PHP ImageCreateFromGif怎么用?PHP ImageCreateFromGif使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImageCreateFromGif函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ImageManipulation
/**
* Contructor method. Will create a new image from the target file.
* Accepts an image filename as a string. Method also works out how
* big the image is and stores this in the $image array.
*
* @param string $imgFile The image filename.
*/
public function ImageManipulation($imgfile)
{
//detect image format
$this->image["format"] = strtolower(substr(strrchr($imgfile, '.'), 1));
$this->image["format"] = strtoupper($this->image["format"]);
// convert image into usable format.
if ($this->image["format"] == "JPG" || $this->image["format"] == "JPEG") {
//JPEG
$this->image["format"] = "JPEG";
$this->image["src"] = ImageCreateFromJPEG($imgfile);
} elseif ($this->image["format"] == "PNG") {
//PNG
$this->image["format"] = "PNG";
$this->image["src"] = imagecreatefrompng($imgfile);
} elseif ($this->image["format"] == "GIF") {
//GIF
$this->image["format"] = "GIF";
$this->image["src"] = ImageCreateFromGif($imgfile);
} elseif ($this->image["format"] == "WBMP") {
//WBMP
$this->image["format"] = "WBMP";
$this->image["src"] = ImageCreateFromWBMP($imgfile);
} else {
//DEFAULT
return false;
}
// Image is ok
$this->imageok = true;
// Work out image size
$this->image["sizex"] = imagesx($this->image["src"]);
$this->image["sizey"] = imagesy($this->image["src"]);
}
示例2: ImageManipulation
/**
* Contructor method. Will create a new image from the target file.
* Accepts an image filename as a string. Method also works out how
* big the image is and stores this in the $image array.
*
* @param string $imgFile The image filename.
*/
public function ImageManipulation($imgfile)
{
//detect image format
$this->image["format"] = preg_replace("/.*\\.(.*)\$/", "\\1", $imgfile);
//$this->image["format"] = preg_replace(".*\.(.*)$", "\\1", $imgfile);
$this->image["format"] = strtoupper($this->image["format"]);
// convert image into usable format.
if ($this->image["format"] == "JPG" || $this->image["format"] == "JPEG") {
//JPEG
$this->image["format"] = "JPEG";
$this->image["src"] = ImageCreateFromJPEG($imgfile);
} elseif ($this->image["format"] == "PNG") {
//PNG
$this->image["format"] = "PNG";
$this->image["src"] = imagecreatefrompng($imgfile);
} elseif ($this->image["format"] == "GIF") {
//GIF
$this->image["format"] = "GIF";
$this->image["src"] = ImageCreateFromGif($imgfile);
} elseif ($this->image["format"] == "WBMP") {
//WBMP
$this->image["format"] = "WBMP";
$this->image["src"] = ImageCreateFromWBMP($imgfile);
} else {
//DEFAULT
return false;
}
// Image is ok
$this->imageok = true;
// Work out image size
$this->image["sizex"] = imagesx($this->image["src"]);
$this->image["sizey"] = imagesy($this->image["src"]);
}
示例3: pcs_href_image
function pcs_href_image($src_path)
{
$strRet = DIR_WS_IMAGES . 'pcs_images/' . basename($src_path) . '_' . MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT . '_' . MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH . '_' . MODULE_ADDONS_PCSLIDESHOW_IMAGE_QUALITY . '.jpg';
#This will be the filename of the resized image.
if (!file_exists($strRet)) {
#Create the file if it does not exist
#check to see if source file exists
if (!file_exists($src_path)) {
return 'error1';
#check to see if source file is readable
} elseif (!is_readable($src_path)) {
return 'error2';
}
#check if gif
if (stristr(strtolower($src_path), '.gif')) {
$oldImage = ImageCreateFromGif($src_path);
} elseif (stristr(strtolower($src_path), '.jpg') || stristr(strtolower($src_path), '.jpeg')) {
$oldImage = ImageCreateFromJpeg($src_path);
} elseif (stristr(strtolower($src_path), '.png')) {
$oldImage = ImageCreateFromPng($src_path);
} else {
return 'error3';
}
#Create the new image
if (function_exists("ImageCreateTrueColor")) {
$newImage = ImageCreateTrueColor(MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT);
} else {
$newImage = ImageCreate(MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT);
}
$backgroundColor = imagecolorallocate($newImage, 255, 255, 255);
imagefill($newImage, 0, 0, $backgroundColor);
#calculate the rezised image's dimmensions
if (imagesx($oldImage) > MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH || imagesy($oldImage) > MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT) {
#Resize image
if (imagesx($oldImage) / MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH > imagesy($oldImage) / MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT) {
#Width is leading in beeing to large
$newWidth = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH;
$newHeight = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH / imagesx($oldImage) * imagesy($oldImage);
} else {
#Height is leading in beeing to large
$newHeight = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT;
$newWidth = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT / imagesy($oldImage) * imagesx($oldImage);
}
} else {
#Don't rezise image
$newWidth = imagesx($oldImage);
$newHeight = imagesy($oldImage);
}
#Copy the old image onto the new image
ImageCopyResampled($newImage, $oldImage, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH / 2 - $newWidth / 2, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT / 2 - $newHeight / 2, 0, 0, $newWidth, $newHeight, imagesx($oldImage), imagesy($oldImage));
imagejpeg($newImage, $strRet, MODULE_ADDONS_PCSLIDESHOW_IMAGE_QUALITY);
#save the image
imagedestroy($oldImage);
#Free Memory
imagedestroy($newImage);
#Free memory
}
return $strRet;
}
示例4: createFromFile
public static function createFromFile($filename, $mime_type, $objAlbum)
{
$objPicture = new clsPicture();
/* Decide which incoming mime type it is. */
switch ($mime_type) {
case 'image/jpeg':
$img = ImageCreateFromJpeg($filename);
break;
case 'image/png':
$img = ImageCreateFromPng($filename);
break;
case 'image/gif':
$img = ImageCreateFromGif($filename);
break;
default:
return 'image_filetype';
}
list($intWidth, $intHeight) = getImageSize($filename);
$intMaxWidth = $objAlbum->get('max_width');
$intMaxHeight = $objAlbum->get('max_height');
if ($intMaxWidth <= 0) {
$intMaxWidth = DEFAULT_X;
}
if ($intMaxHeight <= 0) {
$intMaxHeight = DEFAULT_Y;
}
if ($intWidth > $intMaxWidth || $intHeight > $intMaxHeight) {
/* Check whether the image needs to be resized vertically or horizonally more. */
if ($intWidth / $intMaxWidth > $intHeight / $intMaxHeight) {
/* Right-left needs to have priority. */
$ratio = $intMaxWidth / $intWidth;
} else {
/* Up-down needs to have priority. */
$ratio = $intMaxHeight / $intHeight;
}
$intNewWidth = $intWidth * $ratio;
$intNewHeight = $intHeight * $ratio;
$imgNew = @ImageCreateTrueColor($intNewWidth, $intNewHeight);
if (!@ImageCopyResized($imgNew, $img, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight)) {
return "image_noresize";
}
$intWidth = $intNewWidth;
$intHeight = $intNewHeight;
ImageDestroy($img);
$img = $imgNew;
}
/* This has to be done before setImage() because setImage() needs data from the album. */
$objPicture->set('album_id', $objAlbum->get('id'));
$result = $objPicture->setImage($img);
ImageDestroy($img);
if ($result) {
return $result;
}
$objPicture->set('width', $intWidth);
$objPicture->set('height', $intHeight);
$objPicture->save();
return $objPicture;
}
示例5: ResizeImage
function ResizeImage($Filename, $Thumbnail, $Size)
{
$Path = pathinfo($Filename);
$Extension = $Path['extension'];
$ImageData = @GetImageSize($Filename);
$Width = $ImageData[0];
$Height = $ImageData[1];
if ($Width >= $Height and $Width > $Size) {
$NewWidth = $Size;
$NewHeight = $Size / $Width * $Height;
} elseif ($Height >= $Width and $Height > $Size) {
$NewWidth = $Size / $Height * $Width;
$NewHeight = $Size;
} else {
$NewWidth = $Width;
$NewHeight = $Height;
}
$NewImage = @ImageCreateTrueColor($NewWidth, $NewHeight);
if (preg_match('/^gif$/i', $Extension)) {
$Image = @ImageCreateFromGif($Filename);
} elseif (preg_match('/^png$/i', $Extension)) {
$Image = @ImageCreateFromPng($Filename);
} else {
$Image = @ImageCreateFromJpeg($Filename);
}
if ($ImageData[2] == IMAGETYPE_GIF or $ImageData[2] == IMAGETYPE_PNG) {
$TransIndex = imagecolortransparent($Image);
// If we have a specific transparent color
if ($TransIndex >= 0) {
// Get the original image's transparent color's RGB values
$TransColor = imagecolorsforindex($Image, $TransIndex);
// Allocate the same color in the new image resource
$TransIndex = imagecolorallocate($NewImage, $TransColor['red'], $TransColor['green'], $TransColor['blue']);
// Completely fill the background of the new image with allocated color.
imagefill($NewImage, 0, 0, $TransIndex);
// Set the background color for new image to transparent
imagecolortransparent($NewImage, $TransIndex);
} elseif ($ImageData[2] == IMAGETYPE_PNG) {
// Turn off transparency blending (temporarily)
imagealphablending($NewImage, false);
// Create a new transparent color for image
$color = imagecolorallocatealpha($NewImage, 0, 0, 0, 127);
// Completely fill the background of the new image with allocated color.
imagefill($NewImage, 0, 0, $color);
// Restore transparency blending
imagesavealpha($NewImage, true);
}
}
@ImageCopyResampled($NewImage, $Image, 0, 0, 0, 0, $NewWidth, $NewHeight, $Width, $Height);
if (preg_match('/^gif$/i', $Extension)) {
@ImageGif($NewImage, $Thumbnail);
} elseif (preg_match('/^png$/i', $Extension)) {
@ImagePng($NewImage, $Thumbnail);
} else {
@ImageJpeg($NewImage, $Thumbnail);
}
@chmod($Thumbnail, 0644);
}
示例6: __construct
public function __construct($fileName)
{
// garante que a biblioteca GD está instalado
if (!function_exists("gd_info")) {
echo 'Você não tem a biblioteca GD instalada. Esta classe exige a biblioteca GD para funcionar corretamente.';
exit;
}
// inicializar variáveis
$this->errmsg = '';
$this->error = false;
$this->currentDimensions = array();
$this->newDimensions = array();
$this->fileName = $fileName;
$this->imageMeta = array();
$this->percent = 100;
$this->maxWidth = 0;
$this->maxHeight = 0;
// verifique se o arquivo existe
if (!file_exists($this->fileName)) {
$this->errmsg = 'Arquivo não encontrado';
$this->error = true;
} elseif (!is_readable($this->fileName)) {
$this->errmsg = 'O arquivo não é legível';
$this->error = true;
}
//inicializar os recursos se não houver erros
if ($this->error == false) {
switch (exif_imagetype($this->fileName)) {
case 1:
$this->format = "GIF";
$this->oldImage = ImageCreateFromGif($this->fileName);
break;
case 2:
$this->format = "JPG";
$this->oldImage = @ImageCreateFromJpeg($this->fileName);
break;
case 3:
$this->format = "PNG";
$this->oldImage = ImageCreateFromPng($this->fileName);
break;
default:
$this->errmsg = 'formato de arquivo desconhecido';
$this->error = true;
break;
}
$size = GetImageSize($this->fileName);
$this->currentDimensions = array('width' => $size[0], 'height' => $size[1]);
$this->newImage = $this->oldImage;
$this->gatherImageMeta();
}
if ($this->error == true) {
$this->showErrorImage();
// break;
}
}
示例7: 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);
}
示例8: img_resizer
private static function img_resizer($src, $quality, $w, $h, $saveas)
{
/* v2.5 with auto crop */
$r = 1;
$e = strtolower(substr($src, strrpos($src, ".") + 1, 3));
if ($e == "jpg" || $e == "jpeg") {
$OldImage = imagecreatefromjpeg($src) or $r = 0;
} elseif ($e == "gif") {
$OldImage = ImageCreateFromGif($src) or $r = 0;
} elseif ($e == "bmp") {
$OldImage = ImageCreateFromwbmp($src) or $r = 0;
} elseif ($e == "png") {
$OldImage = ImageCreateFromPng($src) or $r = 0;
} else {
_o("No es una imagen válida! (" . $e . ") -- " . $src);
$r = 0;
}
if ($r) {
list($width, $height) = getimagesize($src);
// check if ratios match
$_ratio = array($width / $height, $w / $h);
if ($_ratio[0] != $_ratio[1]) {
// crop image
// find the right scale to use
$_scale = min((double) ($width / $w), (double) ($height / $h));
// coords to crop
$cropX = (double) ($width - $_scale * $w);
$cropY = (double) ($height - $_scale * $h);
// cropped image size
$cropW = (double) ($width - $cropX);
$cropH = (double) ($height - $cropY);
$crop = ImageCreateTrueColor($cropW, $cropH);
// crop the middle part of the image to fit proportions
ImageCopy($crop, $OldImage, 0, 0, (int) ($cropX / 2), (int) ($cropY / 2), $cropW, $cropH);
}
// do the thumbnail
$NewThumb = ImageCreateTrueColor($w, $h);
if (isset($crop)) {
// been cropped
ImageCopyResampled($NewThumb, $crop, 0, 0, 0, 0, $w, $h, $cropW, $cropH);
ImageDestroy($crop);
} else {
// ratio match, regular resize
ImageCopyResampled($NewThumb, $OldImage, 0, 0, 0, 0, $w, $h, $width, $height);
}
_ckdir($saveas);
ImageJpeg($NewThumb, $saveas, $quality);
ImageDestroy($NewThumb);
ImageDestroy($OldImage);
}
return $r;
}
示例9: createimageByType
private function createimageByType($data, $file)
{
if ($data['type'] === "image/jpeg") {
$image = ImageCreateFromJpeg($file);
}
if ($data['type'] === "image/png") {
$image = ImageCreateFromPng($file);
}
if ($data['type'] === "image/gif") {
$image = ImageCreateFromGif($file);
}
return $image;
}
示例10: create_image_container
private function create_image_container($file, $type)
{
$path = $this->config->item("upload_dir");
if (strtolower($type) === ".jpg" || strtolower($type) === ".jpeg") {
$image = ImageCreateFromJpeg($path . $file . $type);
} elseif (strtolower($type) === ".png") {
$image = ImageCreateFromPng($path . $file . $type);
} elseif (strtolower($type) === ".gif") {
$image = ImageCreateFromGif($path . $file . $type);
} else {
$image = false;
}
return $image;
}
示例11: ImageCreateFromType
function ImageCreateFromType($type,$filename) {
$im = null;
switch ($type) {
case 1:
$im = ImageCreateFromGif($filename);
break;
case 2:
$im = ImageCreateFromJpeg($filename);
break;
case 3:
$im = ImageCreateFromPNG($filename);
break;
}
return $im;
}
示例12: image_resize
function image_resize($upfile, $output_filename, $output_path, $dst_w = 100, $dst_h = 100, $isRadio = 1, $trans_color = array(254, 254, 254))
{
$imagedata = GetImageSize($upfile);
// Read the size
$src_w = $imagedata[0];
$src_h = $imagedata[1];
$src_type = $imagedata[2];
$re_dst_x = 0;
$re_dst_y = 0;
if ($isRadio | 0 > 0) {
if ($dst_w >= $src_w && $dst_h >= $src_h) {
$re_dst_w = $src_w;
$re_dst_h = $src_h;
} else {
$p_w = $dst_w / $src_w;
$p_h = $dst_h / $src_h;
$p = min($p_w, $p_h);
$re_dst_w = $src_w * $p;
$re_dst_h = $src_h * $p;
}
} else {
$re_dst_w = $dst_w;
$re_dst_h = $dst_h;
}
if ($src_type == 1) {
$src_image = ImageCreateFromGif($upfile);
} else {
if ($src_type == 2) {
$src_image = ImageCreateFromJpeg($upfile);
} else {
if ($src_type == 3) {
$src_image = ImageCreateFromPng($upfile);
} else {
if ($src_type == 16) {
$src_image = imagecreatefromxbm($upfile);
}
}
}
}
//else if ($src_type==6)
// return;
$dst_image = imagecreatetruecolor($re_dst_w, $re_dst_h);
$bgc = imagecolorallocate($dst_image, $trans_color[0], $trans_color[1], $trans_color[2]);
imagefilledrectangle($dst_image, 0, 0, $re_dst_w, $re_dst_h, $bgc);
imagecolortransparent($dst_image, $bgc);
imagecopyresampled($dst_image, $src_image, $re_dst_x, $re_dst_y, 0, 0, $re_dst_w, $re_dst_h, $src_w, $src_h);
imagepng($dst_image, $output_path . $output_filename);
}
示例13: getImage
private function getImage($imageUrl)
{
if (!file_get_contents($imageUrl)) {
throw new \Exception("Image not found");
}
$ext = strtolower(array_pop(explode('.', $imageUrl)));
if ($ext == "jpeg" || $ext == "jpg") {
return ImageCreateFromJpeg($imageUrl);
} elseif ($ext == "gif") {
return ImageCreateFromGif($imageUrl);
} elseif ($ext == "png") {
return ImageCreateFromPng($imageUrl);
} else {
throw new \Exception("Image not supported");
}
}
示例14: ImageManipulation
/**
* Contructor method. Will create a new image from the target file.
* Accepts an image filename as a string. Method also works out how
* big the image is and stores this in the $image array.
*
* @param string $imgFile The image filename.
*/
public function ImageManipulation($imgfile)
{
$imageinfo = getimagesize($imgfile);
// debugLog($imageinfo);
//detect image format
//@todo: abstract use mime, and realpathparts not regex
$this->image["format"] = $this->getFileImageType($imgfile);
// convert image into usable format.
if ($this->image["format"] == "JPG" || $this->image["format"] == "JPEG") {
//JPEG
$this->image["format"] = "JPEG";
$this->image["src"] = ImageCreateFromJPEG($imgfile);
} elseif ($this->image["format"] == "PNG") {
//PNG
$this->image["format"] = "PNG";
$this->image["src"] = imagecreatefrompng($imgfile);
} elseif ($this->image["format"] == "GIF") {
//GIF
$this->image["format"] = "GIF";
$this->image["src"] = ImageCreateFromGif($imgfile);
} elseif ($this->image["format"] == "WBMP") {
//WBMP
$this->image["format"] = "WBMP";
$this->image["src"] = ImageCreateFromWBMP($imgfile);
} else {
//DEFAULT
$this->imageok = false;
return false;
}
// Image is ok
$this->imageok = true;
// Work out image size
$this->image['srcfile'] = $imgfile;
$this->image['sizex'] = $imageinfo[0];
$this->image['sizey'] = $imageinfo[1];
$this->image['channels'] = $imageinfo[2];
$this->image['bits'] = $imageinfo['bits'];
$this->image['mime'] = $imageinfo['mime'];
$this->image['width'] = $this->image["sizex"];
$this->image['height'] = $this->image["sizey"];
$this->image["ratio"] = $this->getRatio();
}
示例15: twHoleImg
/**
* Liefert ein Image mit dem Bild aus $dir und $filename.
*/
function twHoleImg($dir, $filename)
{
$dirMitFilename = $dir . $filename;
if (stristr($filename, ".jpg") == true || stristr($datei, ".jpeg") == true) {
if (!($im = ImageCreateFromJPEG($dirMitFilename))) {
echo "Fehler beim laden des Upload-Bildes '" . $dirMitFilename . "'!<br />";
}
} else {
if (stristr($filename, ".gif") == true) {
if (!($im = ImageCreateFromGif($dirMitFilename))) {
echo "Fehler beim laden des Upload-Bildes '" . $dirMitFilename . "'!<br />";
}
} else {
if (stristr($filename, ".png") == true) {
if (!($im = ImageCreateFromPng($dirMitFilename))) {
echo "Fehler beim laden des Upload-Bildes '" . $dirMitFilename . "'!<br />";
}
} else {
echo "Fehler: das ist kein Bildformat: '" . $filename . "'!";
}
}
}
// Fehler-Bild
if ($im == "") {
/*
$im = ImageCreate (150, 30);
$bgc = ImageColorAllocate ($im, 255, 255, 255);
$tc = ImageColorAllocate ($im, 0, 0, 0);
ImageFilledRectangle ($im, 0, 0, 150, 30, $bgc);
ImageString($im, 1, 5, 5, "Fehler beim Öffnen von: $dateiMitPfad", $tc);
*/
return false;
} else {
return $im;
}
}