您的位置:首頁技術文章
文章詳情頁

PHP擴展之圖像處理1——GD庫使用及相關函數

瀏覽:2日期:2022-09-15 17:01:27
范例

Example #1 使用PHP創建PNG格式圖片

<?phpheader('Content-type: image/png');$string = $_GET[’text’];$im = imagecreatefrompng('images/button1.png');$orange = imagecolorallocate($im, 220, 210, 60);$px = (imagesx($im) - 7.5 * strlen($string)) / 2;imagestring($im, 3, $px, 9, $string, $orange);imagepng($im);imagedestroy($im);?>

Example #2 使用 alpha channels 添加水印到圖片

<?php// Load the stamp and the photo to apply the watermark to$stamp = imagecreatefrompng(’stamp.png’);$im = imagecreatefromjpeg(’photo.jpeg’);// Set the margins for the stamp and get the height/width of the stamp image$marge_right = 10;$marge_bottom = 10;$sx = imagesx($stamp);$sy = imagesy($stamp);// Copy the stamp image onto our photo using the margin offsets and the photo// width to calculate positioning of the stamp.imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));// Output and free memoryheader(’Content-type: image/png’);imagepng($im);imagedestroy($im);?>

PHP擴展之圖像處理1——GD庫使用及相關函數

Example #3 使用 imagecopymerge() 創建透明水印

<?php// Load the stamp and the photo to apply the watermark to$im = imagecreatefromjpeg(’photo.jpeg’);// First we create our stamp image manually from GD$stamp = imagecreatetruecolor(100, 70);imagefilledrectangle($stamp, 0, 0, 99, 69, 0x0000FF);imagefilledrectangle($stamp, 9, 9, 90, 60, 0xFFFFFF);$im = imagecreatefromjpeg(’photo.jpeg’);imagestring($stamp, 5, 20, 20, ’libGD’, 0x0000FF);imagestring($stamp, 3, 20, 40, ’(c) 2007-9’, 0x0000FF);// Set the margins for the stamp and get the height/width of the stamp image$marge_right = 10;$marge_bottom = 10;$sx = imagesx($stamp);$sy = imagesy($stamp);// Merge the stamp onto our photo with an opacity of 50%imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);// Save the image to file and free memoryimagepng($im, ’photo_stamp.png’);imagedestroy($im);?>

PHP擴展之圖像處理1——GD庫使用及相關函數

相關函數gd_info — 取得當前安裝的 GD 庫的信息getimagesize — 取得圖像大小getimagesizefromstring — Get the size of an image from a stringimage_type_to_extension — 取得圖像類型的文件后綴image_type_to_mime_type — 取得 getimagesize,exif_read_data,exif_thumbnail,exif_imagetype 所返回的圖像類型的 MIME 類型image2wbmp — 以 WBMP 格式將圖像輸出到瀏覽器或文件imageaffine — Return an image containing the affine tramsformed src image, using an optional clipping areaimageaffinematrixconcat — Concat two matrices (as in doing many ops in one go)imageaffinematrixget — Return an image containing the affine tramsformed src image, using an optional clipping areaimagealphablending — 設定圖像的混色模式imageantialias — 是否使用抗鋸齒(antialias)功能imagearc — 畫橢圓弧imagechar — 水平地畫一個字符imagecharup — 垂直地畫一個字符imagecolorallocate — 為一幅圖像分配顏色imagecolorallocatealpha — 為一幅圖像分配顏色 + alphaimagecolorat — 取得某像素的顏色索引值imagecolorclosest — 取得與指定的顏色最接近的顏色的索引值imagecolorclosestalpha — 取得與指定的顏色加透明度最接近的顏色imagecolorclosesthwb — 取得與給定顏色最接近的色度的黑白色的索引imagecolordeallocate — 取消圖像顏色的分配imagecolorexact — 取得指定顏色的索引值imagecolorexactalpha — 取得指定的顏色加透明度的索引值imagecolormatch — 使一個圖像中調色板版本的顏色與真彩色版本更能匹配imagecolorresolve — 取得指定顏色的索引值或有可能得到的最接近的替代值imagecolorresolvealpha — 取得指定顏色 + alpha 的索引值或有可能得到的最接近的替代值imagecolorset — 給指定調色板索引設定顏色imagecolorsforindex — 取得某索引的顏色imagecolorstotal — 取得一幅圖像的調色板中顏色的數目imagecolortransparent — 將某個顏色定義為透明色imageconvolution — 用系數 div 和 offset 申請一個 3x3 的卷積矩陣imagecopy — 拷貝圖像的一部分imagecopymerge — 拷貝并合并圖像的一部分imagecopymergegray — 用灰度拷貝并合并圖像的一部分imagecopyresampled — 重采樣拷貝部分圖像并調整大小imagecopyresized — 拷貝部分圖像并調整大小imagecreate — 新建一個基于調色板的圖像imagecreatefromgd2 — 從 GD2 文件或 URL 新建一圖像imagecreatefromgd2part — 從給定的 GD2 文件或 URL 中的部分新建一圖像imagecreatefromgd — 從 GD 文件或 URL 新建一圖像imagecreatefromgif — 由文件或 URL 創建一個新圖象。imagecreatefromjpeg — 由文件或 URL 創建一個新圖象。imagecreatefrompng — 由文件或 URL 創建一個新圖象。imagecreatefromstring — 從字符串中的圖像流新建一圖像imagecreatefromwbmp — 由文件或 URL 創建一個新圖象。imagecreatefromwebp — 由文件或 URL 創建一個新圖象。imagecreatefromxbm — 由文件或 URL 創建一個新圖象。imagecreatefromxpm — 由文件或 URL 創建一個新圖象。imagecreatetruecolor — 新建一個真彩色圖像imagecrop — Crop an image using the given coordinates and size, x, y, width and heightimagecropauto — Crop an image automatically using one of the available modesimagedashedline — 畫一虛線imagedestroy — 銷毀一圖像imageellipse — 畫一個橢圓imagefill — 區域填充imagefilledarc — 畫一橢圓弧且填充imagefilledellipse — 畫一橢圓并填充imagefilledpolygon — 畫一多邊形并填充imagefilledrectangle — 畫一矩形并填充imagefilltoborder — 區域填充到指定顏色的邊界為止imagefilter — 對圖像使用過濾器imageflip — Flips an image using a given modeimagefontheight — 取得字體高度imagefontwidth — 取得字體寬度imageftbbox — 給出一個使用 FreeType 2 字體的文本框imagefttext — 使用 FreeType 2 字體將文本寫入圖像imagegammacorrect — 對 GD 圖像應用 gamma 修正imagegd2 — 將 GD2 圖像輸出到瀏覽器或文件imagegd — 將 GD 圖像輸出到瀏覽器或文件imagegif — 輸出圖象到瀏覽器或文件。imagegrabscreen — Captures the whole screenimagegrabwindow — Captures a windowimageinterlace — 激活或禁止隔行掃描imageistruecolor — 檢查圖像是否為真彩色圖像imagejpeg — 輸出圖象到瀏覽器或文件。imagelayereffect — 設定 alpha 混色標志以使用綁定的 libgd 分層效果imageline — 畫一條線段imageloadfont — 載入一新字體imagepalettecopy — 將調色板從一幅圖像拷貝到另一幅imagepalettetotruecolor — Converts a palette based image to true colorimagepng — 以 PNG 格式將圖像輸出到瀏覽器或文件imagepolygon — 畫一個多邊形imagepsbbox — 給出一個使用 PostScript Type1 字體的文本方框imagepsencodefont — 改變字體中的字符編碼矢量imagepsextendfont — 擴充或精簡字體imagepsfreefont — 釋放一個 PostScript Type 1 字體所占用的內存imagepsloadfont — 從文件中加載一個 PostScript Type 1 字體imagepsslantfont — 傾斜某字體imagepstext — 用 PostScript Type1 字體把文本字符串畫在圖像上imagerectangle — 畫一個矩形imagerotate — 用給定角度旋轉圖像imagesavealpha — 設置標記以在保存 PNG 圖像時保存完整的 alpha 通道信息(與單一透明色相反)imagescale — Scale an image using the given new width and heightimagesetbrush — 設定畫線用的畫筆圖像imagesetinterpolation — Set the interpolation methodimagesetpixel — 畫一個單一像素imagesetstyle — 設定畫線的風格imagesetthickness — 設定畫線的寬度imagesettile — 設定用于填充的貼圖imagestring — 水平地畫一行字符串imagestringup — 垂直地畫一行字符串imagesx — 取得圖像寬度imagesy — 取得圖像高度imagetruecolortopalette — 將真彩色圖像轉換為調色板圖像imagettfbbox — 取得使用 TrueType 字體的文本的范圍imagettftext — 用 TrueType 字體向圖像寫入文本imagetypes — 返回當前 PHP 版本所支持的圖像類型imagewbmp — 以 WBMP 格式將圖像輸出到瀏覽器或文件imagewebp — Output an WebP image to browser or fileimagexbm — 將 XBM 圖像輸出到瀏覽器或文件iptcembed — 將二進制 IPTC 數據嵌入到一幅 JPEG 圖像中iptcparse — 將二進制 IPTC 塊解析為單個標記jpeg2wbmp — 將 JPEG 圖像文件轉換為 WBMP 圖像文件png2wbmp — 將 PNG 圖像文件轉換為 WBMP 圖像文件
標簽: PHP
相關文章:
国产综合久久一区二区三区