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

Table of Contents
第一步、安裝ImageMagick
第二步、安裝imagick
第三步、檢查
第四步、測試
第五步、其它格式
附錄:
Home php教程 php手冊 通過 imagick 讓 PHP 生成 PSD 文件縮略圖

通過 imagick 讓 PHP 生成 PSD 文件縮略圖

Jun 06, 2016 pm 07:40 PM
imagick php psd document generate pass

第一步、安裝ImageMagick 首先需要安裝ImageMagick ,因為imagick 是一個可以供 PHP 調(diào)用 ImageMagick 功能的PHP擴展。(目前最新版本是:ImageMagick-6.8.9-5-Q16-x64-dll.exe) 安裝目錄不能有空格,我個人是安裝在 C 盤根目錄: C:\ImageMagick 一路默認

第一步、安裝ImageMagick

  首先需要安裝?ImageMagick ,因為?imagick 是一個可以供 PHP 調(diào)用 ImageMagick 功能的PHP擴展。(目前最新版本是:ImageMagick-6.8.9-5-Q16-x64-dll.exe)

  安裝目錄不能有空格,我個人是安裝在 C 盤根目錄:

C:\ImageMagick

  一路默認安裝即可,安裝完畢后打開 CMD 命令行界面,輸入:convert ,并按回車,如果能看到一大堆的內(nèi)容則表示安裝成功。

  如果提示“ convert 不是內(nèi)部或外部命令,也不是可運行的程序或批處理文件”或者提示“請輸入轉換的盤符”( convert 是一個默認的將 FAT32 轉換到 NTFS 的系統(tǒng)命令)那么你需要自己將 ImageMagick 的安裝路徑添加到系統(tǒng)路徑。

  我的電腦 -> 單擊右鍵 -> 屬性 -> 高級 -> 環(huán)境變量 -> 系統(tǒng)變量 -> 找到“Path” -> 選中并點擊進行編輯 -> 把你的安裝路徑添加進去。

第二步、安裝imagick

  點擊這里下載,注意下載的時候要下對應的 PHP 版本,同時注意系統(tǒng)是32位還是64位,以及 PHP 是 NTS 版還是 TS 版(目前最新穩(wěn)定版是?3.1.2 ,關于如何判斷 PHP 是 NTS 版還是 TS 版,可通過 phpinfo 查看其中的 Thread Safety 項,如果是?enabled 就代表是 TS 版,否之則就是 NTS 版)

  將下載的壓縮包解壓,找到?php_imagick.dll 文件,把它放到 PHP 的擴展目錄里,然后打開 php.ini 文件,在對應的位置添加以下一行:

extension=php_imagick.dll

  保存退出后并重啟電腦,確保生效。

第三步、檢查

  如果一切正常,重啟后在 phpinfo 里應該能看到 imagick 項,如:

通過 imagick 讓 PHP 生成 PSD 文件縮略圖

  如果找不到,則返回第一步,更換不同版本的?ImageMagick 重新安裝并重新調(diào)試。

第四步、測試

  OK,到這一步可以開始編寫代碼了,過程就不細說了,直接上代碼

	error_reporting(E_ERROR | E_WARNING);
	
	$im = new Imagick('1.psd');
	$im->setImageIndex(0);
	$im->setIteratorIndex(0);
	$im->stripImage(); //去除圖片信息
	$im->setImageCompressionQuality(80); //圖片質量
	$im->writeImage('1.jpg');

  以上代碼已經(jīng)經(jīng)過測試可以正確生成出一張 1.jpg 的圖片。

  建議縮略圖還是以 jpg 格式,因為 png 格式不支持壓縮,我在測試的時候使用 30M 的 PSD 文件,生成出來的 png 縮略圖有 3M 多,而 jpg 只有 200KB 左右,并且生成 png 圖片的速度明顯很慢,大概需要3,4秒。

  另外還做了極端測試,用了一近 600M 的 PSD 文件生成 jpg 縮略圖,速度基本在2秒內(nèi),文件大小不到 2.5M ,由于并未對圖片進行尺寸的修改,所以最終生成文件的體積可以根據(jù)實際情況再減小。

第五步、其它格式

  除了 PSD 文件,我還另外嘗試了一些其它格式,比如 MP4 、AVI 等視頻格式,但生成速度超級慢。最后發(fā)現(xiàn)比較實用的就是生成 PDF 文件的縮略圖,但處理 PDF 文件前,需要安裝?Ghostscript ,然后整體的代碼基本和生成 PSD 的代碼一樣

	$im = new Imagick();
	$im->readImage('D:/soft/wamp/www/test/1.pdf[0]');
	//echo $im->getNumberImages();
	$im->writeImages('D:/soft/wamp/www/test/1.jpg', false);

附錄:

  1、php 圖像處理庫 ImageMagick windows 下的安裝

  2、php+Imagick 對 psd 文件的操作

  3、imagick 官方文檔

  4、PHP 中用 imagick 將 PDF 轉成圖片

  5、解決 GhostScript 無法打開中文 PDF 的問題

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 get the current session ID in PHP? How to get the current session ID in PHP? Jul 13, 2025 am 03:02 AM

The method to get the current session ID in PHP is to use the session_id() function, but you must call session_start() to successfully obtain it. 1. Call session_start() to start the session; 2. Use session_id() to read the session ID and output a string similar to abc123def456ghi789; 3. If the return is empty, check whether session_start() is missing, whether the user accesses for the first time, or whether the session is destroyed; 4. The session ID can be used for logging, security verification and cross-request communication, but security needs to be paid attention to. Make sure that the session is correctly enabled and the ID can be obtained successfully.

PHP get substring from a string PHP get substring from a string Jul 13, 2025 am 02:59 AM

To extract substrings from PHP strings, you can use the substr() function, which is syntax substr(string$string,int$start,?int$length=null), and if the length is not specified, it will be intercepted to the end; when processing multi-byte characters such as Chinese, you should use the mb_substr() function to avoid garbled code; if you need to intercept the string according to a specific separator, you can use exploit() or combine strpos() and substr() to implement it, such as extracting file name extensions or domain names.

How do you perform unit testing for php code? How do you perform unit testing for php code? Jul 13, 2025 am 02:54 AM

UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

How to split a string into an array in PHP How to split a string into an array in PHP Jul 13, 2025 am 02:59 AM

In PHP, the most common method is to split the string into an array using the exploit() function. This function divides the string into multiple parts through the specified delimiter and returns an array. The syntax is exploit(separator, string, limit), where separator is the separator, string is the original string, and limit is an optional parameter to control the maximum number of segments. For example $str="apple,banana,orange";$arr=explode(",",$str); The result is ["apple","bana

JavaScript Data Types: Primitive vs Reference JavaScript Data Types: Primitive vs Reference Jul 13, 2025 am 02:43 AM

JavaScript data types are divided into primitive types and reference types. Primitive types include string, number, boolean, null, undefined, and symbol. The values are immutable and copies are copied when assigning values, so they do not affect each other; reference types such as objects, arrays and functions store memory addresses, and variables pointing to the same object will affect each other. Typeof and instanceof can be used to determine types, but pay attention to the historical issues of typeofnull. Understanding these two types of differences can help write more stable and reliable code.

Using std::chrono in C Using std::chrono in C Jul 15, 2025 am 01:30 AM

std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

How to pass a session variable to another page in PHP? How to pass a session variable to another page in PHP? Jul 13, 2025 am 02:39 AM

In PHP, to pass a session variable to another page, the key is to start the session correctly and use the same $_SESSION key name. 1. Before using session variables for each page, it must be called session_start() and placed in the front of the script; 2. Set session variables such as $_SESSION['username']='JohnDoe' on the first page; 3. After calling session_start() on another page, access the variables through the same key name; 4. Make sure that session_start() is called on each page, avoid outputting content in advance, and check that the session storage path on the server is writable; 5. Use ses

How does PHP handle Environment Variables? How does PHP handle Environment Variables? Jul 14, 2025 am 03:01 AM

ToaccessenvironmentvariablesinPHP,usegetenv()orthe$_ENVsuperglobal.1.getenv('VAR_NAME')retrievesaspecificvariable.2.$_ENV['VAR_NAME']accessesvariablesifvariables_orderinphp.iniincludes"E".SetvariablesviaCLIwithVAR=valuephpscript.php,inApach

See all articles