+ -
当前位置:首页 → 问答吧 → 加载类型为 GIF,JPEG,PNG 和BMP 图片的函数

加载类型为 GIF,JPEG,PNG 和BMP 图片的函数

时间:2006-08-28

来源:互联网

复制PHP内容到剪贴板
PHP代码:

<?php 
/* Note: Gif only available with GD Lib ver < 1.6 */ 
function LoadGif ($imgname) { 
    $im = @imagecreatefromgif ($imgname); /* Attempt to open */ 
    if (!$im) { /* See if it failed */ 
        $im = imagecreate (150, 30); /* Create a blank image */ 
        $bgc = imagecolorallocate ($im, 255, 255, 255); 
        $tc = imagecolorallocate ($im, 0, 0, 0); 
        imagefilledrectangle ($im, 0, 0, 150, 30, $bgc); 
        /* Output an errmsg */ 
        imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc); 
    } 
    return $im; 


function LoadJpeg ($imgname) { 
    $im = @imagecreatefromjpeg ($imgname); /* Attempt to open */ 
    if (!$im) { /* See if it failed */ 
        $im  = imagecreate (150, 30); /* Create a blank image */ 
        $bgc = imagecolorallocate ($im, 255, 255, 255); 
        $tc  = imagecolorallocate ($im, 0, 0, 0); 
        imagefilledrectangle ($im, 0, 0, 150, 30, $bgc); 
        /* Output an errmsg */ 
        imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc); 
    } 
    return $im; 


function LoadPNG ($imgname) { 
    $im = @imagecreatefrompng ($imgname); /* Attempt to open */ 
    if (!$im) { /* See if it failed */ 
        $im  = imagecreate (150, 30); /* Create a blank image */ 
        $bgc = imagecolorallocate ($im, 255, 255, 255); 
        $tc  = imagecolorallocate ($im, 0, 0, 0); 
        imagefilledrectangle ($im, 0, 0, 150, 30, $bgc); 
        /* Output an errmsg */ 
        imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc); 
    } 
    return $im; 


/* Note: Gif only available with GD Lib ver >= 1.8 */ 
function LoadWBMP ($imgname) { 
    $im = @imagecreatefromwbmp ($imgname); /* Attempt to open */ 
    if (!$im) { /* See if it failed */ 
        $im  = imagecreate (20, 20); /* Create a blank image */ 
        $bgc = imagecolorallocate ($im, 255, 255, 255); 
        $tc  = imagecolorallocate ($im, 0, 0, 0); 
        imagefilledrectangle ($im, 0, 0, 10, 10, $bgc); 
        /* Output an errmsg */ 
        imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc); 
    } 
    return $im; 

?>

作者: xiaojia   发布时间: 2006-08-28

那这个有什么应用的地方呢?

作者: 野草   发布时间: 2006-09-11

论坛没有了以前代码的高亮显示功能!

作者: forest   发布时间: 2006-09-11

怎么同时判断要在页面显示的图片是什么格式的呢?

作者: 散步的男人   发布时间: 2006-09-12

不错哦,支持楼主

作者: fnet   发布时间: 2006-09-12

不错。支持一下。

作者: jefsun   发布时间: 2006-09-20