当前位置: 首页>>代码示例>>PHP>>正文


PHP imageCreateFromPNG函数代码示例

本文整理汇总了PHP中imageCreateFromPNG函数的典型用法代码示例。如果您正苦于以下问题:PHP imageCreateFromPNG函数的具体用法?PHP imageCreateFromPNG怎么用?PHP imageCreateFromPNG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了imageCreateFromPNG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _getImageResource

 private function _getImageResource($image_file, $save = FALSE)
 {
     $image_info = getImageSize($image_file);
     if ($save) {
         $this->_image_mime = $image_info['mime'];
     }
     switch ($image_info['mime']) {
         case 'image/gif':
             if ($save) {
                 $this->_image_type = 'gif';
             }
             $img_rs = imageCreateFromGIF($image_file);
             break;
         case 'image/jpeg':
             if ($save) {
                 $this->_image_type = 'jpeg';
             }
             $img_rs = imageCreateFromJPEG($image_file);
             break;
         case 'image/png':
             if ($save) {
                 $this->_image_type = 'png';
             }
             $img_rs = imageCreateFromPNG($image_file);
             imageAlphaBlending($img_rs, TRUE);
             imageSaveAlpha($img_rs, TRUE);
             break;
     }
     return $img_rs;
 }
开发者ID:EmranAhmed,项目名称:envato-watermark-image-replacement,代码行数:30,代码来源:dummy_Image_Replacement.php

示例2: initFromPath

 /**
  * Initialize a layer from a given image path
  * 
  * From an upload form, you can give the "tmp_name" path
  * 
  * @param string $path
  * 
  * @return ImageWorkshopLayer
  */
 public static function initFromPath($path)
 {
     if (file_exists($path) && !is_dir($path)) {
         if (!is_readable($path)) {
             throw new ImageWorkshopException('Can\'t open the file at "' . $path . '" : file is not writable, did you check permissions (755 / 777) ?', static::ERROR_NOT_WRITABLE_FILE);
         }
         $imageSizeInfos = @getImageSize($path);
         $mimeContentType = explode('/', $imageSizeInfos['mime']);
         if (!$mimeContentType || !array_key_exists(1, $mimeContentType)) {
             throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
         }
         $mimeContentType = $mimeContentType[1];
         switch ($mimeContentType) {
             case 'jpeg':
                 $image = imageCreateFromJPEG($path);
                 break;
             case 'gif':
                 $image = imageCreateFromGIF($path);
                 break;
             case 'png':
                 $image = imageCreateFromPNG($path);
                 break;
             default:
                 throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
                 break;
         }
         return new ImageWorkshopLayer($image);
     }
     throw new ImageWorkshopException('No such file found at "' . $path . '"', static::ERROR_IMAGE_NOT_FOUND);
 }
开发者ID:gdragffy,项目名称:ImageWorkshop,代码行数:39,代码来源:ImageWorkshop.php

示例3: gerar_tumbs_real

function gerar_tumbs_real($t_x, $t_y, $qualidade, $c_original, $c_final)
{
    $thumbnail = imagecreatetruecolor($t_x, $t_y);
    $original = $c_original;
    $igInfo = getImageSize($c_original);
    switch ($igInfo['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF) {
                $originalimage = imageCreateFromGIF($original);
            } else {
                $ermsg = MSG_GIF_NOT_COMPATIBLE . '<br />';
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG) {
                $originalimage = imageCreateFromJPEG($original);
            } else {
                $ermsg = MSG_JPG_NOT_COMPATIBLE . '<br />';
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG) {
                $originalimage = imageCreateFromPNG($original);
            } else {
                $ermsg = MSG_PNG_NOT_COMPATIBLE . '<br />';
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP) {
                $originalimage = imageCreateFromWBMP($original);
            } else {
                $ermsg = MSG_WBMP_NOT_COMPATIBLE . '<br />';
            }
            break;
        default:
            $ermsg = $igInfo['mime'] . MSG_FORMAT_NOT_COMPATIBLE . '<br />';
            break;
    }
    $nLargura = $igInfo[0];
    $nAltura = $igInfo[1];
    if ($nLargura > $t_x and $nAltura > $t_y) {
        if ($t_x <= $t_y) {
            $nLargura = (int) ($igInfo[0] * $t_y / $igInfo[1]);
            $nAltura = $t_y;
        } else {
            $nLargura = $t_x;
            $nAltura = (int) ($igInfo[1] * $t_x / $igInfo[0]);
            if ($nAltura < $t_y) {
                $nLargura = (int) ($igInfo[0] * $t_y / $igInfo[1]);
                $nAltura = $t_y;
            }
        }
    }
    $x_pos = $t_x / 2 - $nLargura / 2;
    $y_pos = $t_y / 2 - $nAltura / 2;
    imagecopyresampled($thumbnail, $originalimage, $x_pos, $y_pos, 0, 0, $nLargura, $nAltura, $igInfo[0], $igInfo[1]);
    imagejpeg($thumbnail, $c_final, $qualidade);
    imagedestroy($thumbnail);
    return 'ok';
}
开发者ID:amorimlima,项目名称:Hospital,代码行数:60,代码来源:Thumbs.php

示例4: __construct

 public function __construct($path)
 {
     list($this->width, $this->height, $this->type) = @getImageSize($path);
     if ($this->type == IMAGETYPE_JPEG) {
         $this->image = imageCreateFromJPEG($path);
         $this->extension = 'jpg';
         if (function_exists('exif_read_data')) {
             $this->exif = exif_read_data($path);
         }
         $this->rotateToExifOrientation();
     } else {
         if ($this->type == IMAGETYPE_PNG) {
             $this->image = imageCreateFromPNG($path);
             $this->extension = 'png';
         } else {
             if ($this->type == IMAGETYPE_GIF) {
                 $this->image = imageCreateFromGIF($path);
                 $this->extension = 'gif';
             }
         }
     }
     if ($this->image) {
         $this->valid = true;
     }
 }
开发者ID:Norvares,项目名称:nemex,代码行数:25,代码来源:image.php

示例5: loadPNG

function loadPNG($image_name)
{
    $im = imageCreateFromPNG($image_name);
    if (!$im) {
        sendErrorImageAndDie("Could not load piece image: {$image_name}");
    }
    return $im;
}
开发者ID:adamisom,项目名称:chessimager,代码行数:8,代码来源:ChessImagerUtils.php

示例6: create_thumb

function create_thumb($path, $thumb_path, $width = THUMB_WIDTH, $height = THUMB_HEIGHT)
{
    $image_info = getImageSize($path);
    // see EXIF for faster way
    switch ($image_info['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF) {
                // not the same as IMAGETYPE
                $o_im = @imageCreateFromGIF($path);
            } else {
                throw new Exception('GIF images are not supported');
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG) {
                $o_im = @imageCreateFromJPEG($path);
            } else {
                throw new Exception('JPEG images are not supported');
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG) {
                $o_im = @imageCreateFromPNG($path);
            } else {
                throw new Exception('PNG images are not supported');
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP) {
                $o_im = @imageCreateFromWBMP($path);
            } else {
                throw new Exception('WBMP images are not supported');
            }
            break;
        default:
            throw new Exception($image_info['mime'] . ' images are not supported');
            break;
    }
    list($o_wd, $o_ht, $html_dimension_string) = $image_info;
    $ratio = $o_wd / $o_ht;
    $t_ht = $width;
    $t_wd = $height;
    if (1 > $ratio) {
        $t_wd = round($o_wd * $t_wd / $o_ht);
    } else {
        $t_ht = round($o_ht * $t_ht / $o_wd);
    }
    $t_wd = $t_wd < 1 ? 1 : $t_wd;
    $t_ht = $t_ht < 1 ? 1 : $t_ht;
    $t_im = imageCreateTrueColor($t_wd, $t_ht);
    imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
    imagejpeg($t_im, $thumb_path, 85);
    chmod($thumb_path, 0664);
    imageDestroy($o_im);
    imageDestroy($t_im);
    return array($t_wd, $t_ht);
}
开发者ID:sztanpet,项目名称:aoiboard,代码行数:57,代码来源:functions.php

示例7: resize_image

 public static function resize_image($path_from, $path_to, $content_ext, $max_width, $max_height)
 {
     //if ($content_ext=='') $content_ext=c_file::get_ext($path_from);
     //else
     $content_ext = mb_strtolower($content_ext);
     $im = '';
     switch ($content_ext) {
         case ".jpg":
         case ".jpeg":
             $im = @imageCreateFromJPEG($path_from);
             break;
         case ".png":
             $im = @imageCreateFromPNG($path_from);
             break;
         case ".gif":
             $im = @imageCreateFromGIF($path_from);
             break;
         default:
             return false;
             break;
     }
     if ($im == '') {
         //may be ext is wrong
         $im = @imageCreateFromJPEG($path_from);
         if ($im == '') {
             $im = @imageCreateFromPNG($path_from);
         }
         if ($im == '') {
             $im = @imageCreateFromGIF($path_from);
         }
     }
     if ($im == '') {
         return false;
     }
     if (ImageSX($im) >= ImageSY($im) && ImageSX($im) > $max_width) {
         $thumb_ratio = ImageSY($im) / (ImageSX($im) / $max_width) / $max_height;
         $im_new_th = @ImageCreateTrueColor($max_width, $max_height);
         @imagecopyresampled($im_new_th, $im, 0, 0, (ImageSX($im) - ImageSX($im) * $thumb_ratio) / 1.5, 0, $max_width, $max_height, ImageSX($im) * $thumb_ratio, ImageSY($im));
         @ImageJPEG($im_new_th, $path_to);
         @ImageDestroy($im_new_th);
     } else {
         if (ImageSY($im) > $max_height) {
             $thumb_ratio = ImageSX($im) / (ImageSY($im) / $max_height) / $max_width;
             $im_new_th = @ImageCreateTrueColor($max_width, $max_height);
             @imagecopyresampled($im_new_th, $im, 0, 0, 0, (ImageSY($im) - ImageSY($im) * $thumb_ratio) / 5, $max_width, $max_height, ImageSX($im), ImageSY($im) * $thumb_ratio);
             @ImageJPEG($im_new_th, $path_to);
             @ImageDestroy($im_new_th);
         } else {
             @ImageJPEG($im, $path_to);
         }
     }
     @ImageDestroy($im);
     c_file::set_chmod_chown_chgrp($path_to);
     return true;
 }
开发者ID:Rabotyahoff,项目名称:xml_engine,代码行数:55,代码来源:c_file.php

示例8: indexAction

 public function indexAction()
 {
     $points = $this->getRequest()->get("quantity");
     $currency_id = $this->getRequest()->get("currency");
     $currency = Mage::getModel('rewards/currency')->load($currency_id);
     $skin_dir = Mage::getDesign()->getSkinBaseDir(array('_type' => 'skin')) . "" . DS;
     $font = $skin_dir . $currency->getFont();
     $image = $skin_dir . $currency->getImage();
     $doPrintQty = (int) $currency->getImageWriteQuantity() === 1;
     $imageHeight = (int) $currency->getImageHeight();
     $imageWidth = (int) $currency->getImageWidth();
     $fontSize = (int) $currency->getFontSize();
     $fontColor = (int) $currency->getFontColor();
     $im = imageCreateFromPNG($image);
     $black = imagecolorallocate($im, 0x0, 0x0, 0x0);
     // Path to our ttf font file
     $font_file = $font;
     if ($imageHeight > 0 && $imageWidth > 0) {
         list($width, $height) = getimagesize($image);
         $newwidth = $imageWidth;
         $newheight = $imageHeight;
         // Load
         $resized_im = imagecreatetruecolor($newwidth, $newheight);
         $source = imagecreatefrompng($image);
         // Resize
         imagecopyresized($resized_im, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
         $im = $resized_im;
     }
     //TODO: Externilize customization
     // Draw the text 'PHP Manual' using font size 13
     $img_h = $imageHeight == 0 ? imagesy($im) : $imageHeight;
     $img_w = imagesx($im);
     $font_size = $fontSize;
     $text_color = $fontColor;
     $text = empty($points) ? "" : (int) $points;
     $offsetx = $currency->getTextOffsetX();
     $offsety = $currency->getTextOffsetY();
     if (empty($offsetx)) {
         $offsetx = round($img_w / 2 - strlen($text) * imagefontwidth($font_size) / 2 - 3, 1);
         if ((int) $text > 99) {
             $offsetx += 1;
         }
     }
     if (empty($offsety)) {
         $offsety = round($img_h / 2 + imagefontheight($font_size) / 2, 1);
     }
     if ($doPrintQty) {
         imagefttext($im, $font_size, 0, $offsetx, $offsety, $text_color, $font_file, $text);
     }
     // Output image to the browser
     header('Content-Type: image/png');
     imagepng($im);
     imagedestroy($im);
     exit;
 }
开发者ID:rajarshc,项目名称:Rooja,代码行数:55,代码来源:ImageController.php

示例9: __construct

 public function __construct($fontFace, $fontSize = 18, $width = 40, $height = 40, $chars = 2, $overlayPNG = null)
 {
     $this->width = $width;
     $this->height = $height;
     $this->fontFace = $fontFace;
     $this->fontSize = $fontSize;
     $this->chars = $chars;
     if ($overlayPNG) {
         $this->overlay = imageCreateFromPNG($overlayPNG);
     }
 }
开发者ID:vinicius73,项目名称:laravel-instantavatar,代码行数:11,代码来源:AbstractLib.php

示例10: go

 /**
  * Override the parent's go method because there is no view manager here--we're outputting the image directly.
  */
 public function go()
 {
     $config = Config::getInstance();
     $this->setContentType('image/png');
     $random_num = rand(1000, 99999);
     $_SESSION['ckey'] = md5($random_num);
     $img = rand(1, 4);
     $img_handle = imageCreateFromPNG($config->getValue('source_root_path') . "webapp/assets/img/captcha/bg" . $img . ".PNG");
     $color = ImageColorAllocate($img_handle, 0, 0, 0);
     ImageString($img_handle, 5, 20, 13, $random_num, $color);
     ImagePng($img_handle);
     ImageDestroy($img_handle);
 }
开发者ID:rayyan,项目名称:ThinkUp,代码行数:16,代码来源:class.CaptchaImageController.php

示例11: go

 /**
  * Override the parent's go method because there is no view manager here--we're outputting the image directly.
  */
 public function go()
 {
     $config = Config::getInstance();
     $random_num = rand(1000, 99999);
     $_SESSION['ckey'] = md5($random_num);
     $img = rand(1, 4);
     Utils::defineConstants();
     $captcha_bg_image_path = THINKUP_WEBAPP_PATH . "assets/img/captcha/bg" . $img . ".PNG";
     $img_handle = imageCreateFromPNG($captcha_bg_image_path);
     if ($img_handle === false) {
         echo 'CAPTCHA image could not be created from ' . $captcha_bg_image_path;
     } else {
         $this->setContentType('image/png');
         $color = ImageColorAllocate($img_handle, 0, 0, 0);
         ImageString($img_handle, 5, 20, 13, $random_num, $color);
         ImagePng($img_handle);
         ImageDestroy($img_handle);
     }
 }
开发者ID:unruthless,项目名称:ThinkUp,代码行数:22,代码来源:class.CaptchaImageController.php

示例12: watermask

function watermask($targetfile, $logofile)
{
    $imagetype = array("1" => "gif", "2" => "jpeg", "3" => "png", "4" => "wbmp");
    $targetinfo = getimagesize($targetfile);
    $imagecreatefromfunc = "imagecreatefrom" . $imagetype[$targetinfo[2]];
    $imagefunc = "image" . $imagetype[$targetinfo[2]];
    list($img_w, $img_h) = $targetinfo;
    $watermarkinfo = getimagesize($logofile);
    $watermark = imageCreateFromPNG($logofile);
    list($logo_w, $logo_h) = $watermarkinfo;
    $x = $img_w - $logo_w - 5;
    $y = $img_h - $logo_h - 5;
    $dst_photo = imagecreatetruecolor($img_w, $img_h);
    $target_photo = @$imagecreatefromfunc($targetfile);
    imageCopy($dst_photo, $target_photo, 0, 0, 0, 0, $img_w, $img_h);
    imageCopy($dst_photo, $watermark, $x, $y, 0, 0, $logo_w, $logo_h);
    clearstatcache();
    $imagefunc($dst_photo, $targetfile, 80);
}
开发者ID:kalroot,项目名称:phpweb20demo,代码行数:19,代码来源:test.php

示例13: getCanvas

 public function getCanvas()
 {
     if ($this->_canvas == null) {
         switch ($this->_metrics->sourceFormat) {
             case 1:
                 #GIF
                 $this->_canvas = imageCreateFromGIF($this->filePath);
                 break;
             case 2:
                 #JPG
                 $this->_canvas = imageCreateFromJPEG($this->filePath);
                 break;
             case 3:
                 #PNG
                 $this->_canvas = imageCreateFromPNG($this->filePath);
                 break;
         }
     }
     return $this->_canvas;
 }
开发者ID:RhubarbPHP,项目名称:Module.ImageProcessing,代码行数:20,代码来源:Image.php

示例14: getWaterMarkSource

 private function getWaterMarkSource()
 {
     $imageType = $this->watermarkMetrics[2];
     imageCreateFromPNG($this->watermarkImagePath);
     switch ($imageType) {
         case 1:
             //GIF
             $sourceCanvas = imagecreatefromgif($this->watermarkImagePath);
             break;
         case 2:
             //JPG
             $sourceCanvas = imagecreatefromjpeg($this->watermarkImagePath);
             break;
         case 3:
             //PNG
             $sourceCanvas = imagecreatefrompng($this->watermarkImagePath);
             break;
     }
     return $sourceCanvas;
 }
开发者ID:RhubarbPHP,项目名称:Module.ImageProcessing,代码行数:20,代码来源:ImageProcessAddWatermark.php

示例15: imageConverter

 function imageConverter()
 {
     /* parse arguments */
     $numargs = func_num_args();
     $imagefile = func_get_arg(0);
     $convertedtype = func_get_arg(1);
     $this->finalFilePath = func_get_arg(2);
     $output = 0;
     if ($numargs > 3) {
         $this->output = func_get_arg(3);
     }
     /* ask the type of original file */
     $fileinfo = pathinfo($imagefile);
     $imtype = $fileinfo["extension"];
     $this->imname = basename($fileinfo["basename"], "." . $imtype);
     $this->imtype = $imtype;
     /* create the image variable of original file */
     switch ($imtype) {
         case "gif":
             $this->im = imageCreateFromGIF($imagefile);
             break;
         case "jpg":
             $this->im = imageCreateFromJPEG($imagefile);
             break;
         case "png":
             $this->im = imageCreateFromPNG($imagefile);
             break;
         case "wbmp":
             $this->im = imageCreateFromWBMP($imagefile);
             break;
             /*
             		mail me if you have/find this functionality bellow  */
             /*
             case "swf":
             	$this->im 	= $this->imageCreateFromSWF($imagefile);
             	break;
             */
     }
     /* convert to intended type */
     $this->convertImage($convertedtype);
 }
开发者ID:hyrmedia,项目名称:modules,代码行数:41,代码来源:class.imageconverter.inc.php


注:本文中的imageCreateFromPNG函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。