php基礎五之影像處理

來源:互聯網
上載者:User
這篇文章介紹的內容是關於php基礎之影像處理,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

<!-- 影像處理 --><?php//     圖片處理gd2設定檔修改?><!-- 用圖片處理函數畫一張圖 --><?php//     $img = imagecreatetruecolor(500, 500);//     $red = imagecolorallocate($img, 255, 0, 0);//     $green = imagecolorallocate($img, 0, 255, 0);//     $blue = imagecolorallocate($img, 0, 0, 255);//     $pur = imagecolorallocate($img, 255, 0, 255);//     $yellow = imagecolorallocate($img, 121, 72, 0);    //     imagefilledrectangle($img, 0, 0, 500, 500, $green);//     imageline($img, 0, 0, 500, 500, $red);//     imageline($img, 500, 0, 0, 500, $blue);    //     imagefilledellipse($img, 250, 250, 200, 200, $yellow);    //     imagefilledellipse($img, 200, 200, 300, 300, $blue);    //     imagejpeg($img, 'haha.jpg');//     echo "<img src='haha.jpg'>";//     imagedestroy($img);?><!-- 開發驗證碼(產生驗證碼) --><?php    check_code();    function check_code($width = 100, $height = 50,        $num = 4, $type = 'jpeg'){        $img = imagecreate($width, $height);        $string = '';        for ($i = 0;$i < $num; $i++){            $rand = mt_rand(0, 2);            switch ($rand) {                case 0:                    $ascii = mt_rand(48, 57);                    break;                case 1:                    $ascii = mt_rand(65, 90);                    break;                case 2:                    $ascii = mt_rand(97, 122);                    break;            }            $string .= sprintf('%c', $ascii);        }        imagefilledrectangle($img, 0, 0, $width, $height, randBg($img));        for ($i = 0;$i < 50; $i++){            imagesetpixel($img, mt_rand(0, $width),                 mt_rand(0, $height), randPix($img));        }        for ($i = 0;$i < $num;$i++){            $x = floor($width/$num) * $i + 2;            $y = mt_rand(0, $height - 15);                        imagechar($img, 5, $x, $y, $string[$i], randPix($img));        }                $func = 'image' . $type;        $header = 'Content-type:image/'.$type;        if (function_exists($func)) {            header($header);            $func($img);        }else {           echo '圖片類型不支援';         }        imagedestroy($img);        return $string;    }    function randBg($img){        return imagecolorallocate($img, mt_rand(130, 255),            mt_rand(130, 255), mt_rand(130, 255));    }    function randPix($img){        return imagecolorallocate($img, mt_rand(0, 120),             mt_rand(0, 120), mt_rand(0, 120));    }?><!-- 映像縮放和剪裁技術 --><?php    $image = imagecreatefrompng('fbb.png');        $percent = 0.1;    list($width, $height) = getimagesize('fbb.png');        $new_width = $width * $percent;    $new_height = $height * $percent;        $new_image = imagecreatetruecolor($new_width, $new_height);    imagecopyresampled($new_image, $image, 0, 0,        0, 0, $new_width, $new_height, $width, $height);    header('content-type:image/jpeg');    imagejpeg($new_image);?><!-- 圖片浮水印處理 --><?php    $dst = imagecreatefrompng('http://img.php.cn/upload/course/000/        000/002/5833ebba648cf229.png');    $src = imagecreatefrompng('http://img.php.cn/        upload/course/000/000/002/5833ebe90cc11285.png');    $dst_info = getimagesize('5833ebba648cf229.png');    $src_info = getimagesize('5833ebe90cc11285.png');        $dst_x = $dst_info[0] - $src_info[0];    $dst_y = $dst_info[1] - $src_info[1];    imagecopymerge($dst, $src, $dst_x, $dst_y, 0, 0,         $src_info[0], $src_info[1], 100);    header('Content-type:image/png');    imagepng($dst);    imagedestroy($dst);    imagedestroy($src);?><!-- 做一個智能的圖片浮水印函數 --><?php    ?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.