本文整理汇总了PHP中imageCreateFromPng函数的典型用法代码示例。如果您正苦于以下问题:PHP imageCreateFromPng函数的具体用法?PHP imageCreateFromPng怎么用?PHP imageCreateFromPng使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imageCreateFromPng函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: imageCreateFromAny
function imageCreateFromAny($filepath)
{
list($w, $h, $t, $attr) = getimagesize($filepath);
// [] if you don't have exif you could use getImageSize()
$allowedTypes = array(IMG_GIF, IMG_JPG, IMG_PNG, IMG_WBMP);
if (!in_array($t, $allowedTypes)) {
return false;
}
switch ($t) {
case IMG_GIF:
$im = imageCreateFromGif($filepath);
echo 'type image GIF';
break;
case IMG_JPG:
$im = imageCreateFromJpeg($filepath);
echo 'type image JPG';
break;
case IMG_PNG:
$im = imageCreateFromPng($filepath);
echo 'type image PNG';
break;
case IMG_WBMP:
$im = imageCreateFromwBmp($filepath);
echo 'type image BMP';
break;
}
echo 'source : ' . $filepath . ' | im : ' . $im;
return $im;
}
示例2: load
/**
* Load image from $fileName
*
* @throws Zend_Image_Driver_Exception
* @param string $fileName Path to image
*/
public function load($fileName)
{
parent::load($fileName);
$this->_imageLoaded = false;
$info = getimagesize($fileName);
switch ($this->_type) {
case 'jpg':
$this->_image = imageCreateFromJpeg($fileName);
if ($this->_image !== false) {
$this->_imageLoaded = true;
}
break;
case 'png':
$this->_image = imageCreateFromPng($fileName);
if ($this->_image !== false) {
$this->_imageLoaded = true;
}
break;
case 'gif':
$this->_image = imageCreateFromGif($fileName);
if ($this->_image !== false) {
$this->_imageLoaded = true;
}
break;
}
}
示例3: imageResize
function imageResize($file, $info, $destination)
{
$height = $info[1];
//высота
$width = $info[0];
//ширина
//определяем размеры будущего превью
$y = 150;
if ($width > $height) {
$x = $y * ($width / $height);
} else {
$x = $y / ($height / $width);
}
$to = imageCreateTrueColor($x, $y);
switch ($info['mime']) {
case 'image/jpeg':
$from = imageCreateFromJpeg($file);
break;
case 'image/png':
$from = imageCreateFromPng($file);
break;
case 'image/gif':
$from = imageCreateFromGif($file);
break;
default:
echo "No prevue";
break;
}
imageCopyResampled($to, $from, 0, 0, 0, 0, imageSX($to), imageSY($to), imageSX($from), imageSY($from));
imagepng($to, $destination);
imagedestroy($from);
imagedestroy($to);
}
示例4: image_createThumb
function image_createThumb($src, $dest, $maxWidth, $maxHeight, $quality = 75)
{
if (file_exists($src) && isset($dest)) {
// path info
$destInfo = pathInfo($dest);
// image src size
$srcSize = getImageSize($src);
// image dest size $destSize[0] = width, $destSize[1] = height
$srcRatio = $srcSize[0] / $srcSize[1];
// width/height ratio
$destRatio = $maxWidth / $maxHeight;
if ($destRatio > $srcRatio) {
$destSize[1] = $maxHeight;
$destSize[0] = $maxHeight * $srcRatio;
} else {
$destSize[0] = $maxWidth;
$destSize[1] = $maxWidth / $srcRatio;
}
// path rectification
if ($destInfo['extension'] == "gif") {
$dest = substr_replace($dest, 'jpg', -3);
}
// true color image, with anti-aliasing
$destImage = imageCreateTrueColor($destSize[0], $destSize[1]);
// imageAntiAlias($destImage,true);
// src image
switch ($srcSize[2]) {
case 1:
//GIF
$srcImage = imageCreateFromGif($src);
break;
case 2:
//JPEG
$srcImage = imageCreateFromJpeg($src);
break;
case 3:
//PNG
$srcImage = imageCreateFromPng($src);
break;
default:
return false;
break;
}
// resampling
imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destSize[0], $destSize[1], $srcSize[0], $srcSize[1]);
// generating image
switch ($srcSize[2]) {
case 1:
case 2:
imageJpeg($destImage, $dest, $quality);
break;
case 3:
imagePng($destImage, $dest);
break;
}
return true;
} else {
return 'No such File';
}
}
示例5: anyImgFile2Im
/**
* Using GD lib for get and transform images.
* @see http://php.net/manual/en/function.imagecreatefromjpeg.php#110547
*/
function anyImgFile2Im($fname = NULL)
{
if ($fname) {
$this->setFile($fname);
}
$allowedTypes = [1, 2, 3, 6];
// gif,jpg,png,bmp
if (!in_array($this->ftype, $allowedTypes)) {
return false;
}
switch ($this->ftype) {
case 1:
$im = imageCreateFromGif($this->fname);
break;
case 2:
$im = imageCreateFromJpeg($this->fname);
break;
case 3:
$im = imageCreateFromPng($this->fname);
// echo "\n degug {$this->fname}";
break;
case 6:
$im = imageCreateFromBmp($this->fname);
break;
}
return $im;
}
示例6: load
function load()
{
if ($this->loaded) {
return true;
}
//$size = $this->get_size();
//if (!$size) throw new exception("Failed loading image");
list($this->w, $this->h, $this->type) = getImageSize($this->src);
switch ($this->type) {
case 1:
$this->img = imageCreateFromGif($this->src);
break;
case 2:
$this->img = imageCreateFromJpeg($this->src);
break;
case 3:
$this->img = imageCreateFromPng($this->src);
break;
default:
throw new exception("Unsuported image type");
break;
}
$this->loaded = true;
return true;
}
示例7: get_any_type
protected function get_any_type($srcpath)
{
try {
$this->check_file($srcpath);
$srcSize = getImageSize($srcpath);
switch ($srcSize[2]) {
case 1:
$img = imageCreateFromGif($srcpath);
break;
case 2:
$img = imageCreateFromJpeg($srcpath);
break;
case 3:
$img = imageCreateFromPng($srcpath);
break;
default:
throw new Imgdexception('not possible to get any type - srcpath:' . $srcpath);
break;
}
$image['width'] = $srcSize[0];
$image['height'] = $srcSize[1];
$image['img'] = $img;
return $image;
} catch (Imgdexception $e) {
$e->print_debug(__FILE__, __LINE__);
return false;
}
}
示例8: read
/**
* Read a png image from file
* @param File file of the image
* @return resource internal PHP image resource of the file
*/
public function read(File $file)
{
$this->checkIfReadIsPossible($file, 'png');
$image = imageCreateFromPng($file->getAbsolutePath());
if ($image === false) {
throw new ImageException($file->getPath() . ' is not a valid PNG image');
}
return $image;
}
示例9: mergerImg
private function mergerImg($imgs)
{
list($max_width, $max_height) = getimagesize($imgs['dst']);
$dest = imagecreatefromjpeg($imgs['dst']);
$src = imageCreateFromPng($imgs['src']);
imageAlphaBlending($dest, true);
imageSaveAlpha($dest, true);
self::imagecopymerge_alpha($dest, $src, 0, 0, 0, 0, $max_width, $max_height, 100);
$filename = $this->getFileName('jpg');
// header("Content-type: image/jpeg");
imagejpeg($dest, $filename, 80);
imagedestroy($src);
imagedestroy($dest);
return $filename;
}
示例10: img_create
function img_create($type, $name)
{
if ($type == "gif") {
$im = imageCreateFromGif($name);
} elseif ($type == "jpeg" || $type == "jpg") {
$im = imagecreatefromjpeg($name);
} elseif ($type == "png") {
$im = imageCreateFromPng($name);
} elseif ($type == "bmp") {
$im = imageCreateFromBmp($name);
} else {
return false;
}
return $im;
}
示例11: loadFile
/**
* @see \wcf\system\image\adapter\IImageAdapter::loadFile()
*/
public function loadFile($file)
{
list($this->width, $this->height, $this->type) = getImageSize($file);
switch ($this->type) {
case IMAGETYPE_GIF:
$this->image = imageCreateFromGif($file);
break;
case IMAGETYPE_JPEG:
$this->image = imageCreateFromJpeg($file);
break;
case IMAGETYPE_PNG:
$this->image = imageCreateFromPng($file);
break;
default:
throw new SystemException("Could not read image '" . $file . "', format is not recognized.");
break;
}
}
示例12: loadImage
function loadImage($path)
{
if ($this->image) {
imagedestroy($this->image);
}
$img_sz = getimagesize($path);
switch ($img_sz[2]) {
case 1:
$this->image_type = "GIF";
if (!($this->image = imageCreateFromGif($path))) {
return FALSE;
} else {
return TRUE;
}
break;
case 2:
$this->image_type = "JPG";
if (!($this->image = imageCreateFromJpeg($path))) {
return FALSE;
} else {
return TRUE;
}
break;
case 3:
$this->image_type = "PNG";
if (!($this->image = imageCreateFromPng($path))) {
return FALSE;
} else {
return TRUE;
}
break;
case 4:
$this->image_type = "SWF";
if (!($this->image = imageCreateFromSwf($path))) {
return FALSE;
} else {
return TRUE;
}
break;
default:
return FALSE;
}
}
示例13: __construct
function __construct($filename)
{
$this->_filename = $filename;
list($this->_width, $this->_height) = getimagesize($this->_filename);
$pathinfo = pathinfo($filename);
switch (strtolower($pathinfo['extension'])) {
case 'jpg':
case 'jpeg':
$this->_source = imageCreateFromJpeg($filename);
break;
case 'gif':
$this->_source = imageCreateFromGif($filename);
$this->_createImageCallback = 'imagecreate';
break;
case 'png':
$this->_source = imageCreateFromPng($filename);
break;
default:
throw new Naf_Image_Exception('Unsupported file extension');
break;
}
}
示例14: 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;
}
}
示例15: Header
<?php
$mail["perk"] = "marcin.stozek@gmail.com";
Header("Content-type: image/png");
//$string=implode($argv," ");
$string = $_REQUEST['email'];
//$string="perk";
$im = imageCreateFromPng("./email.png");
$orange = ImageColorAllocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($mail[$string])) / 2;
ImageString($im, 3, $px, 9, $mail[$string], $orange);
ImagePng($im);
ImageDestroy($im);