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

Home php教程 PHP源碼 php生成縮略圖

php生成縮略圖

Jun 08, 2016 pm 05:33 PM
img int nbsp quot

<script>ec(2);</script>

自動微縮圖的生成
????由于圖片的數(shù)據(jù)量比較大,傳遞過程相對較長,所以在用戶瀏覽圖片時,常常希望先
顯示一個圖片的縮略圖。
????雖然在HTML中可以通過指定圖片的寬度和高度來隨意縮放圖片,但是這種方法不會
減少圖片的像素數(shù)目。圖形文件的尺寸沒有改變,當然也不會加快圖片下載的速度了。當
然也可以手動通過圖形軟件生成圖片的縮略圖,但對于大量的圖片展示來說,這個工作量
將十分巨大。為此微縮圖的自動生成程序就被設(shè)計出來了。
????PHP中提供的imagecopyresized函數(shù)就可以用來生成真正的縮賂圖片。該函數(shù)的標推
語法如下:
????語法:int imagecopyresized(int dst_im,int src_im,int dstX,int dstY,
int srcX,int srcY,int dstW,int dstH,int srcW,int srcH);
??返回值:整數(shù)
??函數(shù)種類:圖形處理
??內(nèi)容說明:本函數(shù)可復制新圖,并重新調(diào)整圖片的大小尺寸。參數(shù)都是目的在前,來
源在后。參數(shù)dst im及src_im為圖片的handle。參數(shù)dstX、dstY、srcX、srcY分別為目的
及來源的坐標。參數(shù)dstW、dstH、srcW、srcH分別為來源及目的的寬及高,欲調(diào)整的新圖
的尺寸就在這兒配置。
????下面舉個例子來說明這個函數(shù)的用法,對應的程序thumb.php如程序清單12—5所示。
??程序清單12—5??thumb.php

// 本函數(shù)從源文件取出圖像,設(shè)定成指定大小,并輸出到目的文件
// 源文件格式:gif,jpg,png
// 目的文件格式:gif
// $srcFile:源文件
// $dstFile: 目標文件
// $dstW:目標圖片寬度
// $dstH:目標文件高度
function makethumb($srcFile,$dstFile,$dstW,$dstH)
{
$data = GetImageSize($srcFile,&$info);
switch ($data[2])
{
??case 1:
?? $imgsrc = @ImageCreateFromGIF($srcFile);
?? break;
??case 2:
?? $imgsrc = @ImageCreateFromJPEG($srcFile);
?? break;
??case 3:
?? $imgsrc = @ImageCreateFromPNG($srcFile);
?? break;
}
$srcW = ImageSX($imgsrc);
$srcH = ImageSY($imgsrc);
$ni = ImageCreate($dstW,$dstH);
ImageCopyResized($ni,$imgsrc,0,0,0,0,$dstW,$dstH,$srcW,$srcH);
Imagegif($ni,$dstFile);
// 如果需要輸出到瀏覽器,那么將上一句改為 ImageJpeg($ni);
// 如果需要其他格式的圖片,改動最后一句就可以了
}
?>
在這個例子中,首先通過getimagesize()函數(shù)獲得源圖片的情況,再用 imagecreatefromgif()、
imagecreatefromjpeg()或imagecreatefrompng()創(chuàng)建一個源位圖$imgsrc,然后用
imagecreate()函數(shù)創(chuàng)建一個目標位圖,其長、寬各是源位圖的一半。然后調(diào)用imagecopyresized()
函數(shù),將源位圖縮小后拷貝到目標位圖中,最后再用imagegif()函數(shù)生成縮略圖。
????這里所用到的圖形處理函數(shù)就是由安裝的GD庫提供的,現(xiàn)對其分別進行說明。首先
介紹getimagesize()函數(shù),其標準語法如下。
????語法:array getimagesize(string filename,array [imageinfo]);
????返回值:數(shù)組
????函數(shù)種類:圖形處理
????內(nèi)容說明:本函數(shù)可用來取得GIF、JPEG及PNG??3種WWW上圖片的高與寬,不
需要安裝GD library就可以便用本函數(shù)。返回的數(shù)組有4個元素,返回數(shù)組的第一個元素(索
引值0)是圖片的高度,單位是像素(pixel);第二個元素(索引值1)是圖片的寬度;第三個元
素(索引值2)是圖片的文件格式,其值1為GIF格式、2為JPEG/JPG格式、3為PNG格式;
第四個元素(索引值3)為圖片的高與寬字符串,height=xxx width=yyy。
????通過getimagesize()函數(shù)的應用,能輕易獲取圖片的各種信息。下面給大家舉一個獲取
圖片寬度、高度、格式、文件大小的信息的例子,來進一步領(lǐng)會getimagesize()函數(shù)的使用
技巧。程序imginfo如程序清單12—6所示。
??程序清單12-6??imginfo.php
function getImageInfo($img) //$img為圖像文件絕對路徑
{
$img_info = getimagesize($img);
switch ($img_info[2])
{
??case 1:
?? $imgtype = "GIF";
?? break;
??case 2:
?? $imgtype = "JPG";
?? break;
??case 3:
?? $imgtype = "PNG";
?? break;
}
$img_type = $imgtype."圖像";
$img_size = ceil(filesize($img)/1000)."k"; //獲取文件大小
$new_img_info = array (
??"width"=>$img_info[0],
??"height"=>$img_info[1],
??"type"=>$img_type,
??"size"=>$img_size
??);
print " width";
print $img_info[0];
print " height";
print $img_info[1];
print " format";
print $img_type;
print " size";
print $img_size;
print $new_img_info;
}

$img = "/www/htdocs/images/jf.gif";
getImageInfo($img);
?>
????在程序12-5中要創(chuàng)建一個縮略圖,需要先創(chuàng)建一個用來繪圖的空白的畫布。
ImageCreate函數(shù)可以做到這一點。它將返回一個圖像的標識符,并且需要告訴函數(shù)用像素
計算的畫布有多大(x(寬度)與y(高度))。在程序12-5中用到的圖形創(chuàng)建函數(shù)imagecreate()
的標準語法如下:
????語法:int imagecreate(int x_size,int y_size);
????返回值:整數(shù)
????函數(shù)種類:圖形處理
????內(nèi)容說明:本函數(shù)用來建立一張全空的圖形。參數(shù)x_size、y_size為圖形的尺寸,單位
為像素(pixel)。

????如果要從已經(jīng)存在的圖片中取出圖片文件代碼,可以用imagecreatefromgif()、
imagecreatefromjpeg()或imagecreatefrompng(),例如函數(shù)imagecreatefromgif()就是從一個GIF
格式的圖片文件中取出對應的圖片源代碼,其標準語法如下:
??語法:int imagecreatefromgif(string filename);
??返回值:整數(shù)
??函數(shù)種類:圖形處理
??內(nèi)容說明:本函數(shù)用來取出一張GIF格式圖形,通常作為背景或者基本的畫布樣本使
用。參數(shù)filename可以是本地端的文件,也可以是網(wǎng)絡(luò)的URL地址。返回值為GIF的文件
代碼,可供其他函數(shù)使用。
????在將源位圖縮小后拷貝到目標位圖中時,用到了imagecopyresized()函數(shù),此函數(shù)可以
復制新圖并調(diào)整大小,其標準語法如下:
????語法:int imagecopyresized(int dst_im,int src_im,int dstX,int dstY,int srcX,int srcY,
int dstW,int dstH,int srcW,int srcH);
????返回值:整數(shù)
????函數(shù)種類:圖形處理

????內(nèi)容說明:本函數(shù)可復制新圖,并重新調(diào)整圖片的大小尺寸。參數(shù)那是目的在前,來
源在后。參數(shù)ddst_im及src_im為圖片的handle。參數(shù)dstX、dstY、srcX、srcY分別為目的
及來源的坐標。參數(shù)dstW、dstH、srcW、srcH分別為來源及目的的寬及高,若欲調(diào)整新圖
的尺寸就在這里配置。
????最后在輸出圖像時用到的imagegif()函數(shù)的標準語法如下:
????語法:int imagegif(int im,string [filename]);
????返問值:整數(shù)
????函數(shù)種類:圖形處理
????內(nèi)容說明:本函數(shù)用來建立一張GIF格式圖形。參數(shù)im為使用ImageCreate()所建立
的圖片代碼,參數(shù)filename可省略,若無本參數(shù)filename,則會將圖片直接送到瀏覽器端,
記得在送出圖片之前要先送出使用Content-type:image/gif的標頭字符串(header)到瀏覽器
端,以順利傳輸圖片。若要使用透明背景的GIF圖,也就是GIF89a的格式,需要先使用
ImageColorTransparent()配置透明背景。本函數(shù)產(chǎn)生的GIF圖,由于有版權(quán)的問題,因此
在商業(yè)上的使用還要多加考慮。

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)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

How to open img file How to open img file Sep 18, 2023 am 09:40 AM

Methods to open img files include using virtual optical drive software, using compression software, and using special tools. Detailed introduction: 1. Use virtual optical drive software to open, download and install a virtual optical drive software, right-click the img file, select "Open with" or "Associated Program", select the installed virtual optical drive software in the pop-up dialog box, virtual The optical drive software will automatically load the img file and use it as a disc image in the virtual optical drive. Double-click the disc icon in the virtual optical drive to open the img file and access its contents, etc.

How to change title bar color on Windows 11? How to change title bar color on Windows 11? Sep 14, 2023 pm 03:33 PM

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

How to enable or disable taskbar thumbnail previews on Windows 11 How to enable or disable taskbar thumbnail previews on Windows 11 Sep 15, 2023 pm 03:57 PM

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

OOBELANGUAGE Error Problems in Windows 11/10 Repair OOBELANGUAGE Error Problems in Windows 11/10 Repair Jul 16, 2023 pm 03:29 PM

Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

Display scaling guide on Windows 11 Display scaling guide on Windows 11 Sep 19, 2023 pm 06:45 PM

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

See all articles