国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 php手冊 PHP腳本的10個技巧(轉(zhuǎn)自ZDNet) --動態(tài)創(chuàng)建圖象

PHP腳本的10個技巧(轉(zhuǎn)自ZDNet) --動態(tài)創(chuàng)建圖象

Jun 21, 2016 am 09:12 AM
image the

創(chuàng)建|動態(tài)|技巧|腳本

動態(tài)創(chuàng)建圖象

在安裝了某些第三方函數(shù)庫之后,結(jié)合你的圖形處理技能,你就可以用PHP創(chuàng)建和處理圖像了。事實上,你也不需要太高的幾何學(xué)知識。我在中學(xué)的時候這門功課總是不及格,現(xiàn)在不也照樣會用PHP創(chuàng)建圖像!

在使用基本的圖像創(chuàng)建函數(shù)之前,你需要安裝GD庫。如果要用到和JPEG相關(guān)的圖像創(chuàng)建函數(shù)你還需要安裝jpeg-6b。在圖像中使用Type 1字體的時候還必須安裝t1lib。

在這里,你還需要對你的系統(tǒng)進(jìn)行進(jìn)一步地調(diào)整。首先,你必須安裝t1lib以提供圖象處理支持,接下來要安裝jpeg-6b。第三步是安裝GD函數(shù)庫。你得按順序做完這三件工作,原因是你需要編譯GD庫才能使用jpeg-6b庫,如果jpeg-6b步首先安裝,編譯就會出錯,到那時候你就是忙的團(tuán)團(tuán)轉(zhuǎn)也沒辦法了。

在安裝完以上的三個函數(shù)庫之后,你還要重新配置PHP。這可是你在安裝PHP的DSO版本時的拿手好戲噢!接著執(zhí)行make clean,命令,然后在當(dāng)前配置指示符里加入以下代碼:

--with-gd=[/path/to/gd]
--with-jpeg-dir=[/path/to/jpeg-6b]
--with-t1lib=[/path/to/t1lib]

最后順序執(zhí)行make、make install命令完成配制任務(wù)。重新啟動 Apache,運行phpinfo()函數(shù)檢查性新功能是否正常運行。

和你安裝的GD庫有關(guān),你可能或者不可能具有創(chuàng)建GIF或者PNG圖像的能力。關(guān)鍵在于:如果你已經(jīng)安裝了gd-1.6或者早期版本,那么你可以處理GIF但不能處理PNG。如果安裝了gd-1.6或者以后版本,你可以處理PNG但又不能處理GIF。

創(chuàng)建一個簡單的圖像需要采用好幾個函數(shù)。我會按步驟帶你學(xué)習(xí)這一過程:

輸出一個文件頭,其中包含了你所創(chuàng)建圖像的MIME類型,在我們的例子中就是PNG。

header ("Content-type: image/png");

使用ImageCreate()創(chuàng)建一個變量存放空白圖像。該函數(shù)需要以像素為單位的圖像大小。格式是ImageCreate(x_size, y_size),對250-X-250像素的圖像而言,用法如下:

$newImg = ImageCreate(250,250);

因為你的圖像現(xiàn)在還是空白,所以你還要設(shè)法用某些色彩填滿它,但是,首先你需要按照顏色的RGB值為每種顏色分配名字,這要用到ImageColorAllocate()函數(shù)。函數(shù)的格式是ImageColorAllocate([image], [red], [green], [blue])。如果是天藍(lán)色,具體代碼如下:

$skyblue = ImageColorAllocate($newImg,136,193,255);

接著,你需要調(diào)用ImageFill()函數(shù)為圖像填充以上的顏色。ImageFill(),函數(shù)有好幾個版本,比如ImageFillRectangle(), ImageFillPolygon()等等。為簡單起見,我們就采用ImageFill()函數(shù)進(jìn)行顏色填充,格式如下:

ImageFill([image], [start x point], [start y point], [color])
ImageFill($newImg,0,0,$skyblue);

最后,你創(chuàng)建了圖像并破壞圖像流以釋放內(nèi)存:

ImagePNG($newImg);
ImageDestroy($newImg); ?>

具體的代碼看起來很像下面的樣子:

header ("Content-type: image/png");
$newImg = ImageCreate(250,250);
$skyblue = ImageColorAllocate($newImg,136,193,255);
ImageFill($newImg,0,0,$skyblue);
ImagePNG($newImg);
ImageDestroy($newImg);
?>

如果你調(diào)用這個腳本skyblue.php 并用自己的瀏覽器訪問它,你就會看到一個250-X-250像素大的藍(lán)色PNG圖像。

你還可以用圖像創(chuàng)建函數(shù)處理圖像,比如創(chuàng)建大型圖像的縮微圖等。

假設(shè)你打算為某個圖片制作一個35-X-35像素大小的縮微圖。你要做到就是創(chuàng)建一個新的35 X 35 像素大小的圖像;制造出一個包含其原始圖像內(nèi)容的圖像流;然后改變原始圖像的大小,并把它放到新的空白圖像中去。

用來達(dá)到以上目的的關(guān)鍵函數(shù)就是ImageCopyResized(),,該函數(shù)的格式如下所示:ImageCopyResized([new image handle],[original image handle],[new image X], [new Image Y], [original image X], [original image Y], [new image X], [new image Y], [original image X], [original image Y]);

以下是代碼注釋。

/* send a header so that the browser knows the content-type of the file */
header("Content-type: image/png");

/* set up variables to hold the height and width of your new image */
$newWidth = 35;
$newHeight = 35;

/* create a blank, new image of the given new height and width */
$newImg = ImageCreate($newWidth,$newHeight);

/* get the data from the original, large image */
$origImg = ImageCreateFromPNG("test.png");

/* copy the resized image. Use the ImageSX() and ImageSY functions to get the x and y sizes of the orginal image. */
ImageCopyResized($newImg,$origImg,0,0,0,0,$newWidth,$newHeight,ImageSX($origImg),ImageSY($origImg));

/* create final image and free up the memory */
ImagePNG($newImg);
ImageDestroy($newImg); ?>

如果你調(diào)用了以上腳本resized.php 并用自己的瀏覽器訪問它,你應(yīng)該能看到一個35-X-35像素大小的縮微PNG圖。



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

After 2 months, the humanoid robot Walker S can fold clothes After 2 months, the humanoid robot Walker S can fold clothes Apr 03, 2024 am 08:01 AM

Editor of Machine Power Report: Wu Xin The domestic version of the humanoid robot + large model team completed the operation task of complex flexible materials such as folding clothes for the first time. With the unveiling of Figure01, which integrates OpenAI's multi-modal large model, the related progress of domestic peers has been attracting attention. Just yesterday, UBTECH, China's "number one humanoid robot stock", released the first demo of the humanoid robot WalkerS that is deeply integrated with Baidu Wenxin's large model, showing some interesting new features. Now, WalkerS, blessed by Baidu Wenxin’s large model capabilities, looks like this. Like Figure01, WalkerS does not move around, but stands behind a desk to complete a series of tasks. It can follow human commands and fold clothes

How to use Bing Image Creator for free How to use Bing Image Creator for free Feb 27, 2024 am 11:04 AM

This article will introduce seven ways to get high-quality output using the free BingImageCreator. BingImageCreator (now known as ImageCreator for Microsoft Designer) is one of the great online artificial intelligence art generators. It generates highly realistic visual effects based on user prompts. The more specific, clear, and creative your prompts are, the better the results will be. BingImageCreator has made significant progress in creating high-quality images. It now uses Dall-E3 training mode, showing a higher level of detail and realism. However, its ability to consistently produce HD results depends on several factors, including fast

How to delete images from Xiaomi phones How to delete images from Xiaomi phones Mar 02, 2024 pm 05:34 PM

How to delete images on Xiaomi mobile phones? You can delete images on Xiaomi mobile phones, but most users don’t know how to delete images. Next is the tutorial on how to delete images on Xiaomi mobile phones brought by the editor. Interested users can come and join us. Let's see! How to delete images on Xiaomi mobile phone 1. First open the [Album] function in Xiaomi mobile phone; 2. Then check the unnecessary pictures and click the [Delete] button in the lower right corner; 3. Then click [Album] at the top to enter the special area , select [Recycle Bin]; 4. Then directly click [Empty Recycle Bin] as shown in the figure below; 5. Finally, directly click [Permanent Delete] to complete.

Imagemagic installation Centos and Image installation tutorial Imagemagic installation Centos and Image installation tutorial Feb 12, 2024 pm 05:27 PM

LINUX is an open source operating system. Its flexibility and customizability make it the first choice of many developers and system administrators. In the LINUX system, image processing is a very important task, and Imagemagick and Image are Two very popular image processing tools, this article will introduce you to how to install Imagemagick and Image in Centos system, and provide detailed installation tutorials. Imagemagic installation Centos tutorial Imagemagick is a powerful image processing toolset, which can perform various image operations under the command line. The following are the steps to install Imagemagick on Centos system: 1

What currency is THE? Is THE coin worth investing in? What currency is THE? Is THE coin worth investing in? Feb 21, 2024 pm 03:49 PM

What currency is THE? THE (Tokenized Healthcare Ecosystem) is a digital currency that uses blockchain technology to focus on innovation and reform in the healthcare industry. THE coin's mission is to use blockchain technology to improve the efficiency and transparency of the medical industry and promote more efficient cooperation among all parties, including patients, medical staff, pharmaceutical companies and medical institutions. The Value and Characteristics of THE Coin First of all, THE Coin, as a digital currency, has the advantages of blockchain - decentralization, high security, transparent transactions, etc., allowing participants to trust and rely on this system. Secondly, the uniqueness of THE coin is that it focuses on the medical and health industry, using blockchain technology to transform the traditional medical system and improve

How to check the latest price of The Sandbox coin? How to check the latest price of The Sandbox coin? Mar 05, 2024 am 11:52 AM

How to check the latest price of TheSandbox currency TheSandbox is a decentralized gaming platform built on the Ethereum blockchain. Land, assets and gaming experiences can be purchased using its native token SAND. The steps to check the latest price of SAND are as follows: Choose a reliable price check website or app. Some commonly used price query websites include: CoinMarketCap: https://coinmarketcap.com/Coindesk: https://www.coindesk.com/Binance: https://www.binance.com/ Search on the website or app SAND. View SAND

imagefilledrectangle() function in PHP imagefilledrectangle() function in PHP Aug 30, 2023 am 09:05 AM

The imagefilledrectangle() function draws a filled rectangle. Syntax imagefilledrectangle($img,$x1,$y1,$x2,$y2,$color) Parameters image Use imagecreatetruecolor() to create a blank image. x1The x coordinate of point 1. y1 The y coordinate of point 1. x2 x coordinate of point 2. y2 The y coordinate of point 2. color fill color. Return value imagefilledrectangle() function returns successfully

Samsung's new foldable screen product exposed, expected to debut in late July Samsung's new foldable screen product exposed, expected to debut in late July Mar 21, 2024 pm 02:16 PM

Samsung plans to launch a new generation of Galaxy Z Fold and Flip 6 series folding screen smartphones in the second half of this year. Recently, Korean media TheElec and "Jiji Weekly e" revealed more details about these two new products. Samsung Galazy Z Fold6 leaked pictures. Source @chunvn8888 According to TheElec, Samsung Electronics’ supply chain manufacturers are expected to start the production of Galaxy Z Fold6 and Flip 6 related components in early May. In contrast, the production of parts for Galaxy Z Fold5 and Flip 5 started in the second half of May last year. This means that this year’s release schedule for the standard version of the Galaxy Z series is about two to three weeks earlier than last year. go

See all articles