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

Home Backend Development PHP Tutorial 用php和imagemagick來處理圖片文件的上傳和縮放處理(轉(zhuǎn)貼)_PHP

用php和imagemagick來處理圖片文件的上傳和縮放處理(轉(zhuǎn)貼)_PHP

Jun 01, 2016 pm 12:32 PM
image upload image picture deal with document Table of contents conduct

用php和imagemagick來處理圖片文件的上傳和縮放處理
php處理文件的上傳是很簡(jiǎn)便的,但是如果要對(duì)上傳的圖片進(jìn)行縮放處理的話,雖說能用GD來做,但是
要進(jìn)行比較繁瑣的處理。ImageMagick是一個(gè)圖像處理包,一般的Linux軟件包中都會(huì)有的。它包含了許
多處理圖像的工具,它可以進(jìn)行圖像文件格式的轉(zhuǎn)化還可以對(duì)圖像進(jìn)行各種處理,其中我們將用到它的
圖像縮放功能。這個(gè)通過它的軟件包中的工具convert來實(shí)現(xiàn),這樣來調(diào)用
????????convert -geometry 寬x高 源文件 縮放后的文件
????????
請(qǐng)?jiān)诋?dāng)前目錄下建立一個(gè)images的目錄,并且能讓web執(zhí)行用戶可寫,這個(gè)目錄用來存放上載后的圖片和

縮放的圖片。
底下是一個(gè)簡(jiǎn)單小例子,包括圖片上傳和處理,在RedHat6.0+php3.0.12下測(cè)試通過。

uploadform.html:文件上傳表單

〈HTML>
〈HEAD>
〈TITLE>選擇文件〈/TITLE>
〈/HEAD>
〈BODY ALIGN="CENTER">
〈FORM ENCTYPE="multipart/form-data" ACTION="upload.php3" METHOD=POST>
選擇圖片文件: 〈INPUT NAME="image" TYPE="file">
〈INPUT TYPE="submit" VALUE="Send File">
〈/FORM>
〈/BODY>
〈/HTML>


upload.php3:處理上傳后的圖片文件

〈html>
〈head>
〈title>處理〈/title>
〈/head>
〈body>
〈?
$flag = "true";
if(isset($image) && $image &&
????????($image_type = "image/gif" || $image_type = "image/png"
????????????????|| $image_type = "image/pjpeg")){???????//判斷上載文件的格式等
????????$dest_image = "./images/".$image_name;
????????if(@copy($image,$dest_image)){??//拷貝上載文件到images目錄下

???????????$small_image = "./images/small".$image_name;
???????????$exec_str = "/usr/bin/X11/convert -geometry 100x100 ".$dest_image." ".$small_image;?????????????
???????????@exec($exec_str);???????//進(jìn)行圖像的縮放
????????}else
????????????????$flag = "false";

}else{

????????
????????$flag = "false";
}

if( $flag == "false"){
????????echo "error〈p>";
????????echo "〈a href=\"uploadform.html\">重新上載〈/a>";
}else{
????????echo "〈image src=\"$small_image\">";
????????echo "〈image src=\"./images/$image_name\">";
}???????
?>
〈/body>
〈/html>

如果結(jié)合GetImageSize函數(shù),我們還可以控制縮放的大小。結(jié)合數(shù)據(jù)庫(kù)可以對(duì)圖片文件進(jìn)行索引或者存儲(chǔ)等。
ImageMagick的功能是很強(qiáng)大的,不僅能對(duì)圖片文件進(jìn)行縮放,還有進(jìn)行翻轉(zhuǎn)、格式轉(zhuǎn)化等等功能。
讀者可以自己參看ImageMagick的幫助文件。

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)

How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? Where is the automatically saved image when posting? How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? Where is the automatically saved image when posting? Mar 22, 2024 am 08:06 AM

With the continuous development of social media, Xiaohongshu has become a platform for more and more young people to share their lives and discover beautiful things. Many users are troubled by auto-save issues when posting images. So, how to solve this problem? 1. How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? 1. Clear the cache First, we can try to clear the cache data of Xiaohongshu. The steps are as follows: (1) Open Xiaohongshu and click the "My" button in the lower right corner; (2) On the personal center page, find "Settings" and click it; (3) Scroll down and find the "Clear Cache" option. Click OK. After clearing the cache, re-enter Xiaohongshu and try to post pictures to see if the automatic saving problem is solved. 2. Update the Xiaohongshu version to ensure that your Xiaohongshu

How to post pictures in TikTok comments? Where is the entrance to the pictures in the comment area? How to post pictures in TikTok comments? Where is the entrance to the pictures in the comment area? Mar 21, 2024 pm 09:12 PM

With the popularity of Douyin short videos, user interactions in the comment area have become more colorful. Some users wish to share images in comments to better express their opinions or emotions. So, how to post pictures in TikTok comments? This article will answer this question in detail and provide you with some related tips and precautions. 1. How to post pictures in Douyin comments? 1. Open Douyin: First, you need to open Douyin APP and log in to your account. 2. Find the comment area: When browsing or posting a short video, find the place where you want to comment and click the "Comment" button. 3. Enter your comment content: Enter your comment content in the comment area. 4. Choose to send a picture: In the interface for entering comment content, you will see a "picture" button or a "+" button, click

The operation process of WIN10 service host occupying too much CPU The operation process of WIN10 service host occupying too much CPU Mar 27, 2024 pm 02:41 PM

1. First, we right-click the blank space of the taskbar and select the [Task Manager] option, or right-click the start logo, and then select the [Task Manager] option. 2. In the opened Task Manager interface, we click the [Services] tab on the far right. 3. In the opened [Service] tab, click the [Open Service] option below. 4. In the [Services] window that opens, right-click the [InternetConnectionSharing(ICS)] service, and then select the [Properties] option. 5. In the properties window that opens, change [Open with] to [Disabled], click [Apply] and then click [OK]. 6. Click the start logo, then click the shutdown button, select [Restart], and complete the computer restart.

How to make ppt pictures appear one by one How to make ppt pictures appear one by one Mar 25, 2024 pm 04:00 PM

In PowerPoint, it is a common technique to display pictures one by one, which can be achieved by setting animation effects. This guide details the steps to implement this technique, including basic setup, image insertion, adding animation, and adjusting animation order and timing. Additionally, advanced settings and adjustments are provided, such as using triggers, adjusting animation speed and order, and previewing animation effects. By following these steps and tips, users can easily set up pictures to appear one after another in PowerPoint, thereby enhancing the visual impact of the presentation and grabbing the attention of the audience.

What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. Mar 21, 2024 pm 09:17 PM

When deleting or decompressing a folder on your computer, sometimes a prompt dialog box "Error 0x80004005: Unspecified Error" will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

What should I do if the images on the webpage cannot be loaded? 6 solutions What should I do if the images on the webpage cannot be loaded? 6 solutions Mar 15, 2024 am 10:30 AM

Some netizens found that when they opened the browser web page, the pictures on the web page could not be loaded for a long time. What happened? I checked that the network is normal, so where is the problem? The editor below will introduce to you six solutions to the problem that web page images cannot be loaded. Web page images cannot be loaded: 1. Internet speed problem The web page cannot display images. It may be because the computer's Internet speed is relatively slow and there are more softwares opened on the computer. And the images we access are relatively large, which may be due to loading timeout. As a result, the picture cannot be displayed. You can turn off the software that consumes more network speed. You can go to the task manager to check. 2. Too many visitors. If the webpage cannot display pictures, it may be because the webpages we visited were visited at the same time.

How to arrange two pictures side by side in wps document How to arrange two pictures side by side in wps document Mar 20, 2024 pm 04:00 PM

When using WPS office software, we found that not only one form is used, tables and pictures can be added to the text, pictures can also be added to the table, etc. These are all used together to make the content of the entire document look richer. , if you need to insert two pictures into the document and they need to be arranged side by side. Our next course can solve this problem: how to place two pictures side by side in a wps document. 1. First, you need to open the WPS software and find the picture you want to adjust. Left-click the picture and a menu bar will pop up, select "Page Layout". 2. Select "Tight wrapping" in text wrapping. 3. After all the pictures you need are confirmed to be set to "Tight text wrapping", you can drag the pictures to the appropriate position and click on the first picture.

Learn how to handle special characters and convert single quotes in PHP Learn how to handle special characters and convert single quotes in PHP Mar 27, 2024 pm 12:39 PM

In the process of PHP development, dealing with special characters is a common problem, especially in string processing, special characters are often escaped. Among them, converting special characters into single quotes is a relatively common requirement, because in PHP, single quotes are a common way to wrap strings. In this article, we will explain how to handle special character conversion single quotes in PHP and provide specific code examples. In PHP, special characters include but are not limited to single quotes ('), double quotes ("), backslash (), etc. In strings

See all articles