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


PHP imagecreatefrompng函数代码示例

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


在下文中一共展示了imagecreatefrompng函数的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;
     }
 }
开发者ID:nyan-cat,项目名称:easyweb,代码行数:32,代码来源:image.php

示例2: 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

示例3: createImage

 /**
  * @param $text
  * @return resource
  */
 private function createImage($text)
 {
     if (!is_string($text) || trim($text) == '') {
         $text = 'ERROR';
     }
     // Create an image from captchaBackground.png
     $image = imagecreatefrompng(realpath('bundles/comun/images/captchaBackground.png'));
     // Set the font colour
     $colour = imagecolorallocate($image, 183, 178, 152);
     // Set the font
     //$font = '../fonts/Anorexia.ttf';
     $font = realpath('bundles/comun/fonts/Anorexia.ttf');
     // Set a random integer for the rotation between -15 and 15 degrees
     $rotate = rand(-15, 15);
     // Create an image using our original image and adding the detail
     imagettftext($image, 14, $rotate, 18, 30, $colour, $font, $text);
     // Output the image as a png
     //imagepng($image);
     /*return new Response(
           $captchaText,
           200,
           array(
               'Content-Type' => 'image/png',
               'Cache-Control' => 'no-cache'
           )
       );*/
     return $image;
 }
开发者ID:jorgemunoz8807,项目名称:ociosos,代码行数:32,代码来源:Captcha.php

示例4: 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"]);
 }
开发者ID:ali-codehoppers,项目名称:adventskalender,代码行数:40,代码来源:ImageManipulation.php

示例5: 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

示例6: 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

示例7: resize

function resize($photo_src, $width, $name)
{
    $parametr = getimagesize($photo_src);
    list($width_orig, $height_orig) = getimagesize($photo_src);
    $ratio_orig = $width_orig / $height_orig;
    $new_width = $width;
    $new_height = $width / $ratio_orig;
    $newpic = imagecreatetruecolor($new_width, $new_height);
    $col2 = imagecolorallocate($newpic, 255, 255, 255);
    imagefilledrectangle($newpic, 0, 0, $new_width, $new_width, $col2);
    switch ($parametr[2]) {
        case 1:
            $image = imagecreatefromgif($photo_src);
            break;
        case 2:
            $image = imagecreatefromjpeg($photo_src);
            break;
        case 3:
            $image = imagecreatefrompng($photo_src);
            break;
    }
    imagecopyresampled($newpic, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
    imagejpeg($newpic, $name, 100);
    return true;
}
开发者ID:pioytazsko,项目名称:garantmarket,代码行数:25,代码来源:new_item.php

示例8: colorImageBottom

/**
 *  Retourne la couleur du pixel en bas a gauche de l'image
 **/
function colorImageBottom($imageName)
{
    // recuperer le type et la taille de l'image
    // Pb sur certains JPG qui retourne ''
    list($imgW, $imgH, $imgTyp) = getimagesize($imageName);
    switch ($imgTyp) {
        case 1:
            $im = imagecreatefromgif($imageName);
            break;
        case 2:
        case ' ':
            $im = imagecreatefromjpeg($imageName);
            break;
        case 3:
            $im = imagecreatefrompng($imageName);
            break;
        default:
            $app = JFactory::getApplication();
            $app->enqueueMessage(JTEXT::_('IMGNAME_ERROR') . '[name=' . $imageName . '] [ type=' . $imgTyp . '] [ format= ' . $imgW . 'x' . $imgH, 'error');
            var_dump(gd_info());
            return "";
    }
    $rgb = imagecolorat($im, 2, $imgH - 2);
    $hex = sprintf("%06X", $rgb);
    return $hex;
}
开发者ID:sansandeep143,项目名称:av,代码行数:29,代码来源:helper.php

示例9: cropnsave

 public function cropnsave($id)
 {
     $basepath = app_path() . '/storage/uploads/';
     $jpeg_quality = 90;
     $src = $basepath . 'resize_' . $id;
     if (ImageModel::getImgTypeByExtension($id) == ImageModel::IMGTYPE_PNG) {
         $img_r = imagecreatefrompng($src);
     } else {
         $img_r = imagecreatefromjpeg($src);
     }
     $dst_r = ImageCreateTrueColor(Input::get('w'), Input::get('h'));
     imagecopyresampled($dst_r, $img_r, 0, 0, Input::get('x'), Input::get('y'), Input::get('w'), Input::get('h'), Input::get('w'), Input::get('h'));
     $filename = $basepath . 'crop_' . $id;
     imagejpeg($dst_r, $filename, $jpeg_quality);
     $image = ImageModel::createImageModel('crop_' . $id);
     try {
         $session = Session::get('user');
         $userService = new SoapClient(Config::get('wsdl.user'));
         $currentUser = $userService->getUserById(array("userId" => $session['data']->id));
         $currentUser = $currentUser->user;
         $currentUser->avatar = $image;
         $result = $userService->updateUser(array("user" => $currentUser));
         // Cleanup
         File::delete($src);
         File::delete($filename);
         File::delete($basepath . $id);
         return Response::json($result->complete);
     } catch (Exception $ex) {
         error_log($ex);
     }
 }
开发者ID:Yatko,项目名称:Gifteng,代码行数:31,代码来源:ImageController.php

示例10: __construct

 public function __construct($filepath)
 {
     if (!function_exists('gd_info')) {
         throw new Hayate_Exception(_('GD extension is missing.'));
     }
     if (!is_file($filepath)) {
         throw new Hayate_Exception(sprintf(_('Cannot find %s'), $filepath));
     }
     $this->filepath = $filepath;
     $info = getimagesize($this->filepath);
     if (false === $info) {
         throw new Hayate_Exception(sprintf(_('Cannot read %s'), $filepath));
     }
     list($this->width, $this->height) = $info;
     $mimes = array('image/jpeg' => 'jpg', 'image/pjpeg' => 'jpg', 'image/gif' => 'gif', 'image/png' => 'png');
     $this->ext = isset($mimes[$info['mime']]) ? $mimes[$info['mime']] : null;
     if (null === $this->ext) {
         throw new Hayate_Exception(sprintf(_('Supported mime types are: %s'), implode(',', array_keys($mimes))));
     }
     switch ($this->ext) {
         case 'jpg':
             $this->img = imagecreatefromjpeg($filepath);
             break;
         case 'gif':
             $this->img = imagecreatefromgif($filepath);
             break;
         case 'png':
             $this->img = imagecreatefrompng($filepath);
             break;
     }
 }
开发者ID:hayate,项目名称:hayate,代码行数:31,代码来源:Image.php

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: foundation_process_image_file

function foundation_process_image_file($file_name, $setting_name)
{
    if ($setting_name->domain == FOUNDATION_SETTING_DOMAIN && $setting_name->name == 'logo_image') {
        // Need to make sure this isn't too big
        if (function_exists('getimagesize') && function_exists('imagecreatefrompng') && function_exists('imagecopyresampled') && function_exists('imagepng')) {
            $size = getimagesize($file_name);
            if ($size) {
                $width = $size[0];
                $height = $size[1];
                if ($size['mime'] == 'image/png') {
                    if ($width > FOUNDATION_MAX_LOGO_SIZE) {
                        $new_width = FOUNDATION_MAX_LOGO_SIZE;
                        $new_height = $height * $new_width / $width;
                        $src_image = imagecreatefrompng($file_name);
                        $saved_image = imagecreatetruecolor($new_width, $new_height);
                        // Preserve Transparency
                        imagecolortransparent($saved_image, imagecolorallocate($saved_image, 0, 0, 0));
                        imagecopyresampled($saved_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                        // Get rid of the old file
                        unlink($file_name);
                        // New image, compression level 5 (make it a bit smaller)
                        imagepng($saved_image, $file_name, 5);
                    }
                }
            }
        }
    }
}
开发者ID:sb-xs,项目名称:que-pour-elle,代码行数:28,代码来源:root-functions.php


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