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


PHP GetImageSize函数代码示例

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


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

示例1: newGalleryImage

 static function newGalleryImage($image)
 {
     # Grab filename and image type from upload
     $file_ext = self::$imageTypes[$image['type']];
     $filename = $image['name'];
     # Upload of image
     copy($image['tmp_name'], "gallery_images/" . $filename);
     # Grabs file suffix for variable function calls
     $function_suffix = strtoupper($file_ext);
     # Variable read/write functions for image creation
     $function_to_read = 'ImageCreateFrom' . $function_suffix;
     $function_to_write = 'Image' . $function_suffix;
     # Determine the file size and create a proportionally sized thumbnail
     $size = GetImageSize("gallery_images/" . $filename);
     if ($size[0] > $size[1]) {
         $thumbnail_width = 200;
         $thumbnail_height = (int) (200 * $size[1] / $size[0]);
     } else {
         $thumbnail_width = (int) (200 * $size[0] / $size[1]);
         $thumbnail_height = 200;
     }
     $source_handle = $function_to_read("gallery_images/" . $filename);
     if ($source_handle) {
         $destination_handle = ImageCreateTrueColor($thumbnail_width, $thumbnail_height);
         ImageCopyResampled($destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]);
     }
     $function_to_write($destination_handle, "gallery_images/tb/" . $filename);
 }
开发者ID:michaeljmatthews22,项目名称:dightHum,代码行数:28,代码来源:class.Gallery.php

示例2: makeThumb1

 /**
  * 把图片生成缩略图1
  * @param string $srcFile	源文件			
  * @param string $dstFile	目标文件
  * @param int $dstW		目标图片宽度		
  * @param int $dstH		目标文件高度
  * @param string $dstFormat	目标文件生成的格式, 有png和jpg两种格式
  * @return 错误返回错误对象
  */
 public static function makeThumb1($srcFile, $dstFile, $dstW, $dstH, $dstFormat = "png")
 {
     //打开图片
     $data = GetImageSize($srcFile, &$info);
     switch ($data[2]) {
         case 1:
             $im = @ImageCreateFromGIF($srcFile);
             break;
         case 2:
             $im = @imagecreatefromjpeg($srcFile);
             break;
         case 3:
             $im = @ImageCreateFromPNG($srcFile);
             break;
     }
     if (!$im) {
         throw new TM_Exception(__CLASS__ . ": Create image failed");
     }
     //设定图片大小
     $srcW = ImageSX($im);
     $srcH = ImageSY($im);
     $ni = ImageCreate($dstW, $dstH);
     ImageCopyResized($ni, $im, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
     //生成指定格式的图片
     if ($dstFormat == "png") {
         imagepng($ni, $dstFile);
     } elseif ($dstFormat == "jpg") {
         ImageJpeg($ni, $dstFile);
     } else {
         imagepng($ni, $dstFile);
     }
 }
开发者ID:heiyeluren,项目名称:tmphp,代码行数:41,代码来源:TM_Image.class.php

示例3: resizeImg

function resizeImg($origPath, $mW, $mH)
{
    // Read the size
    $rst['size'] = GetImageSize($origPath);
    $w = $rst['size'][0];
    $h = $rst['size'][1];
    // Proportionally resize the image to the max sizes specified above
    $xRatio = $mW / $w;
    $yRatio = $mH / $h;
    if ($w <= $mW && $h <= $mH) {
        $tnW = $w;
        $tnH = $h;
    } elseif ($xRatio * $h < $mH) {
        $tnH = ceil($xRatio * $h);
        $tnW = $mW;
    } else {
        $tnW = ceil($yRatio * $w);
        $tnH = $mH;
    }
    // Create the new image!
    if ($rst['size']['mime'] == 'image/jpg' || $rst['size']['mime'] == 'image/jpeg') {
        $rst['src'] = imagecreatefromjpeg($origPath);
        $rst['dst'] = ImageCreateTrueColor($tnW, $tnH);
        $rst['resize'] = ImageCopyResized($rst['dst'], $rst['src'], 0, 0, 0, 0, $tnW, $tnH, $w, $h);
        $rst['imgMod'] = imagejpeg($rst['dst'], $origPath, 100);
    } else {
        $rst['note'] = 'Error with file type!';
        return false;
    }
    return $rst;
}
开发者ID:badwolfgirl,项目名称:Reporting-System,代码行数:31,代码来源:uploadify.php

示例4: ThumbnailImage

 function ThumbnailImage($path, $maxdimension = 100)
 {
     $this->maxdimension = $maxdimension;
     //check path
     is_file($path) or die("File: {$path} doesn't exist.");
     //check type
     $extension = substr($path, strpos($path, ".") + 1);
     $extension = strtolower($extension);
     in_array($extension, $this->types) or die("Incorrect file type.");
     $this->fileextension = $extension;
     $this->setMimeType($extension);
     //get dimensions by creating imageproperties
     $this->imageproperties = GetImageSize($path);
     //create image
     if ($extension == "jpeg" || $extension == "jpg") {
         $this->image = imagecreatefromJPEG($path);
     } elseif ($extension == "gif") {
         $this->image = imagecreatefromGIF($path);
     } elseif ($extension == "png") {
         $this->image = imagecreatefromPNG($path);
     } else {
         die("Couldn't create image.");
     }
     $this->createThumb();
 }
开发者ID:Team1619,项目名称:cowaterj,代码行数:25,代码来源:ThumbnailImage.php

示例5: upload_image_and_thumbnail

 function upload_image_and_thumbnail($fileData, $size, $subFolder, $prefix)
 {
     if (strlen($fileData['name']) > 4) {
         $error = 0;
         $destFolder = WWW_ROOT . $subFolder;
         $realFileName = $fileData['name'];
         if (!is_dir($destFolder)) {
             mkdir($destFolder, true);
         }
         $filetype = $this->getFileExtension($fileData['name']);
         $filetype = strtolower($filetype);
         if (!in_array($fileData['type'], $this->contentType)) {
             return false;
             exit;
         } else {
             if ($fileData['size'] > 700000) {
                 return false;
                 exit;
             } else {
                 $imgsize = GetImageSize($fileData['tmp_name']);
             }
         }
         if (is_uploaded_file($fileData['tmp_name'])) {
             if (!copy($fileData['tmp_name'], $destFolder . '/' . $realFileName)) {
                 return false;
                 exit;
             } else {
                 $this->resize_img($destFolder . '/' . $realFileName, $size, $destFolder . '/' . $prefix . $realFileName);
                 unlink($destFolder . '/' . $realFileName);
             }
         }
         return $fileData;
     }
 }
开发者ID:pritten,项目名称:SmartCitizen.me,代码行数:34,代码来源:image.php

示例6: image_replace

    /**
     * Parses image-replace properties
     * @access public
     * @param $url
     * @return string
     */
    public function image_replace($value)
    {
        $url = preg_match('/
				(?:url\\(\\s*)?      	 # maybe url(
				[\'"]?               # maybe quote
				([^\'\\"\\)]*)                # 1 = URI
				[\'"]?               # maybe end quote
				(?:\\s*\\))?         # maybe )
			/xs', $value, $match);
        if ($match) {
            $url = $match[1];
            // Get the size of the image file
            $size = GetImageSize($this->source->find($url));
            $width = $size[0];
            $height = $size[1];
            // Make sure theres a value so it doesn't break the css
            if (!$width && !$height) {
                $width = $height = 0;
            }
            // Build the selector
            $properties = 'background:url(' . $url . ') no-repeat 0 0;height:0;padding-top:' . $height . 'px;width:' . $width . 'px;display:block;text-indent:-9999px;overflow:hidden;';
            return $properties;
        }
        return false;
    }
开发者ID:pdclark,项目名称:Scaffold,代码行数:31,代码来源:ImageReplace.php

示例7: getSize

function getSize($pic)
{
    global $width, $height;
    $size = GetImageSize($pic);
    $width = $size[0];
    $height = $size[1];
}
开发者ID:adamfranco,项目名称:segue-1.x,代码行数:7,代码来源:getsize.php

示例8: loadFile

 public function loadFile($thumbnail, $image)
 {
     $imgData = @GetImageSize($image);
     if (!$imgData) {
         throw new Exception(sprintf('Could not load image %s', $image));
     }
     if (in_array($imgData['mime'], $this->imgTypes)) {
         $loader = $this->imgLoaders[$imgData['mime']];
         if (!function_exists($loader)) {
             throw new Exception(sprintf('Function %s not available. Please enable the GD extension.', $loader));
         }
         $this->source = $loader($image);
         $this->sourceWidth = $imgData[0];
         $this->sourceHeight = $imgData[1];
         $this->sourceMime = $imgData['mime'];
         $thumbnail->initThumb($this->sourceWidth, $this->sourceHeight, $this->maxWidth, $this->maxHeight, $this->scale, $this->inflate);
         $this->thumb = imagecreatetruecolor($thumbnail->getThumbWidth(), $thumbnail->getThumbHeight());
         if ($imgData[0] == $this->maxWidth && $imgData[1] == $this->maxHeight) {
             $this->thumb = $this->source;
         } else {
             imagecopyresampled($this->thumb, $this->source, 0, 0, 0, 0, $thumbnail->getThumbWidth(), $thumbnail->getThumbHeight(), $imgData[0], $imgData[1]);
         }
         return true;
     } else {
         throw new Exception(sprintf('Image MIME type %s not supported', $imgData['mime']));
     }
 }
开发者ID:net7,项目名称:Talia-CMS,代码行数:27,代码来源:sfGDAdapter.class.php

示例9: getImageType

 public static function getImageType($srcFile)
 {
     $data = @GetImageSize($srcFile);
     if ($data === false) {
         return false;
     } else {
         switch ($data[2]) {
             case 1:
                 return 'gif';
                 break;
             case 2:
                 return 'jpg';
                 break;
             case 3:
                 return 'png';
                 break;
             case 4:
                 return 'swf';
                 break;
             case 5:
                 return 'psd';
                 break;
             case 6:
                 return 'bmp';
                 break;
             case 7:
                 return 'tiff';
                 break;
             case 8:
                 return 'tiff';
                 break;
             case 9:
                 return 'jpc';
                 break;
             case 10:
                 return 'jp2';
                 break;
             case 11:
                 return 'jpx';
                 break;
             case 12:
                 return 'jb2';
                 break;
             case 13:
                 return 'swc';
                 break;
             case 14:
                 return 'iff';
                 break;
             case 15:
                 return 'wbmp';
                 break;
             case 16:
                 return 'xbm';
                 break;
             default:
                 return false;
         }
     }
 }
开发者ID:BGCX261,项目名称:zr4u-svn-to-git,代码行数:60,代码来源:page.php

示例10: __construct

 /**
  * Construction for class
  *
  * @param string $sourceFolder : end with slash '/'
  * @param string $sourceName
  * @param string $destFolder : end with slash '/'
  * @param string $destName
  * @param int $maxWidth
  * @param int $maxHeight
  * @param string $cropRatio
  * @param int $quality
  * @param string $color
  *
  * @return ImageResizer
  */
 public function __construct($sourceFolder, $sourceName, $destFolder, $destName, $maxWidth = 0, $maxHeight = 0, $cropRatio = '', $quality = 90, $color = 'ffffff')
 {
     $this->sourceFolder = $sourceFolder;
     $this->sourceName = $sourceName;
     $this->destFolder = $destFolder;
     $this->destName = $destName;
     $this->maxWidth = $maxWidth;
     $this->maxHeight = $maxHeight;
     $this->cropRatio = $cropRatio;
     $this->quality = $quality;
     $this->color = $color;
     if (!file_exists($this->sourceFolder . $this->sourceName)) {
         echo 'Error: image does not exist: ' . $this->sourceFolder . $this->sourceName;
         return null;
     }
     $size = GetImageSize($this->sourceFolder . $this->sourceName);
     $mime = $size['mime'];
     // Make sure that the requested file is actually an image
     if (substr($mime, 0, 6) != 'image/') {
         echo 'Error: requested file is not an accepted type: ' . $this->sourceFolder . $this->sourceName;
         return null;
     }
     $this->size = $size;
     if ($color != '') {
         $this->color = preg_replace('/[^0-9a-fA-F]/', '', $color);
     } else {
         $this->color = false;
     }
 }
开发者ID:phannguyenvn,项目名称:test-git,代码行数:44,代码来源:ImageResize.php

示例11: post_process

 /**
  * The second last process, should only be getting everything
  * syntaxically correct, rather than doing any heavy processing
  *
  * @author Anthony Short
  * @return $css string
  */
 public static function post_process()
 {
     if ($found = CSS::find_properties_with_value('image-replace', 'url\\([\'\\"]?([^)]+)[\'\\"]?\\)')) {
         foreach ($found[4] as $key => $value) {
             $path = $url = str_replace("\\", "/", unquote($value));
             # If they're getting an absolute file
             if ($path[0] == "/") {
                 $path = DOCROOT . ltrim($path, "/");
             }
             # Check if it exists
             if (!file_exists($path)) {
                 FB::log("ImageReplace - Image doesn't exist " . $path);
             }
             # Make sure it's an image
             if (!is_image($path)) {
                 FB::log("ImageReplace - File is not an image: {$path}");
             }
             // Get the size of the image file
             $size = GetImageSize($path);
             $width = $size[0];
             $height = $size[1];
             // Make sure theres a value so it doesn't break the css
             if (!$width && !$height) {
                 $width = $height = 0;
             }
             // Build the selector
             $properties = "\n\t\t\t\t\tbackground:url({$url}) no-repeat 0 0;\n\t\t\t\t\theight:{$height}px;\n\t\t\t\t\twidth:{$width}px;\n\t\t\t\t\tdisplay:block;\n\t\t\t\t\ttext-indent:-9999px;\n\t\t\t\t\toverflow:hidden;\n\t\t\t\t";
             CSS::replace($found[2][$key], $properties);
         }
         # Remove any left overs
         CSS::replace($found[1], '');
     }
 }
开发者ID:Keukendeur,项目名称:csscaffold,代码行数:40,代码来源:ImageReplace.php

示例12: resizeImage

 private function resizeImage($file, $data, $tmd = 600, $quality = 100)
 {
     $data['type'] = "image/jpeg";
     $basename = basename($file);
     $filesDir = $this->input->post('uploadDir');
     // хэш нередактируемой карты!
     $uploaddir = implode(array($this->input->server('DOCUMENT_ROOT'), 'storage', $tmd, $filesDir), DIRECTORY_SEPARATOR);
     $srcFile = implode(array($this->input->server('DOCUMENT_ROOT'), 'storage', 'source', $filesDir, $basename), DIRECTORY_SEPARATOR);
     $image = $this->createimageByType($data, $srcFile);
     if (!file_exists($uploaddir)) {
         mkdir($uploaddir, 0775, true);
     }
     $size = GetImageSize($srcFile);
     $new = ImageCreateTrueColor($size['1'], $size['0']);
     if ($size['1'] > $tmd || $size['0'] > $tmd) {
         if ($size['1'] < $size['0']) {
             $hNew = round($tmd * $size['1'] / $size['0']);
             $new = ImageCreateTrueColor($tmd, $hNew);
             ImageCopyResampled($new, $image, 0, 0, 0, 0, $tmd, $hNew, $size['0'], $size['1']);
         }
         if ($size['1'] >= $size['0']) {
             $hNew = round($tmd * $size['0'] / $size['1']);
             $new = ImageCreateTrueColor($hNew, $tmd);
             ImageCopyResampled($new, $image, 0, 0, 0, 0, $hNew, $tmd, $size['0'], $size['1']);
         }
     }
     //print $uploaddir."/".TMD."/".$filename.".jpg<br>";
     imageJpeg($new, $uploaddir . DIRECTORY_SEPARATOR . $basename, $quality);
     //header("content-type: image/jpeg");// активировать для отладки
     //imageJpeg ($new, "", 100);//активировать для отладки
     imageDestroy($new);
 }
开发者ID:korzhevdp,项目名称:freehand,代码行数:32,代码来源:upload.php

示例13: get_gallery

 /**
  * Fetches gallery info for the specified gallery and immediate children.
  */
 function get_gallery($gallery_name, $getChildGalleries = 1)
 {
     $gal = new gallery($gallery_name);
     //if fail then try to open generic metadata
     $fp = @fopen($this->config->base_path . $this->config->pathto_galleries . $gallery_name . "/metadata.csv", "r");
     if ($fp) {
         while ($temp[] = fgetcsv($fp, 2048)) {
         }
         fclose($fp);
         list($gal->filename, $gal->name, $gal->desc, $gal->long_desc, $gal->date) = $temp[1];
         for ($i = 0; $i < count($temp) - 3; $i++) {
             $gal->images[$i] = new image();
             list($gal->images[$i]->filename, $gal->images[$i]->name, $gal->images[$i]->desc, $gal->images[$i]->long_desc, $gal->images[$i]->date, $gal->images[$i]->sort) = $temp[$i + 2];
             $gal->images[$i]->full_path = $gal->name . "/" . $gal->images[$i]->filename;
             //get image size and type
             list($gal->images[$i]->width, $gal->images[$i]->height, $gal->images[$i]->type) = substr($gal->images[$i]->filename, 0, 7) == "http://" ? @GetImageSize($gal->images[$i]->filename) : @GetImageSize($this->config->base_path . $this->config->pathto_galleries . $gal->id . "/" . $gal->images[$i]->filename);
         }
         //discover child galleries
         $dir = photostack::get_listing($this->config->base_path . $this->config->pathto_galleries . $gallery_name . "/", "dirs");
         if ($getChildGalleries) {
             //but only fetch their info if required too
             foreach ($dir->dirs as $gallery) {
                 $gal->galleries[] = $this->get_gallery($gallery_name . "/" . $gallery, $getChildGalleries);
             }
         } else {
             //otherwise just copy their names in so they can be counted
             $gal->galleries = $dir->dirs;
         }
         return $gal;
     } else {
         return parent::get_gallery($gallery_name, $getChildGalleries);
     }
 }
开发者ID:noeljackson,项目名称:PhotoStack,代码行数:36,代码来源:io_csv.class.php

示例14: validate_image

 function validate_image($data, $size = '', $hlimit = '', $vlimit = '')
 {
     $exts = array('gif', 'jpg', 'jpeg', 'png');
     $fname = $data['name'];
     $tmpname = $data['tmp_name'];
     $ext = preg_replace('/.*\\./', '', $fname);
     $res = '';
     // Check the image extension
     $res = 0;
     foreach ($exts as $key) {
         $res |= preg_match('/^' . $key . '$/', $ext);
     }
     if ($res) {
         $image_size = GetImageSize($tmpname);
         $w = $image_size[0];
         $h = $image_size[1];
         $r = validate_image_cmpiterator($data['size'], $size, 'Размер', 1, 'байт');
         if ($r != '') {
             return $r;
         }
         $r = validate_image_cmpiterator($w, $hlimit, 'Ширина', 0, 'пикселей');
         if ($r != '') {
             return $r;
         }
         $r = validate_image_cmpiterator($h, $vlimit, 'Высота', 0, 'пикселей');
         if ($r != '') {
             return $r;
         }
         return '';
     } else {
         return 'Поддерживаются только следующие расширения файлов: gif, jpg, jpeg, png.';
     }
 }
开发者ID:Nazg-Gul,项目名称:e-marsa,代码行数:33,代码来源:image_validator.php

示例15: login

 function login($type = "")
 {
     $this->obj->db->where('app_users_list.username', $this->obj->input->post('email'));
     $this->obj->db->where('password', $this->_prep_password($this->obj->input->post('password')));
     $this->obj->db->where('status_active', '1');
     $this->obj->db->join('app_users_profile', 'app_users_profile.id=app_users_list.id', 'right');
     $this->obj->db->limit(1);
     $Q = $this->obj->db->get($this->table);
     if ($Q->num_rows() > 0) {
         $user = $Q->row();
         $this->_start_session($user);
         $this->obj->db->where('id', $this->obj->session->userdata('id'));
         $p = $this->obj->db->get($this->table_profile);
         $profile = $p->row();
         if ($profile->avatar != "" && @GetImageSize($profile->avatar)) {
             $profile->avatar = $profile->avatar;
         } else {
             $profile->avatar = base_url() . "media/images/profile.jpeg";
         }
         $profile = array('avatar' => $profile->avatar, 'name_display' => $profile->name_display);
         $this->obj->session->set_userdata($profile);
         $this->obj->db->update('app_users_list', array('online' => 1, 'last_login' => time()), array('id' => $user->id));
         $this->_log($type . ' Login successful...');
         $this->obj->session->set_flashdata('notification', 'Login successful...');
         return true;
     } else {
         $this->_destroy_session();
         $this->_log($type . ' Login failed...');
         $this->obj->session->set_flashdata('notification', 'Login failed...');
         return false;
     }
 }
开发者ID:viktoredz,项目名称:bpom-spkp,代码行数:32,代码来源:User.php


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