📄 imagick.examples.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Examples</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="imagick.constants.html">Predefined Constants</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.imagick.html">The Imagick class</a></div> <div class="up"><a href="book.imagick.html">ImageMagick</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div> <h1>Examples</h1> <div id="imagick.examples-1" class="section"> <h2 class="title">Examples</h2> <p class="para"> Imagick makes image manipulation in PHP extremely easy through an OO interface. Here is a quick example on how to make a thumbnail: <div class="example"> <p><b>Example #1 Creating a thumbnail in Imagick</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br />header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-type: image/jpeg'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$image </span><span style="color: #007700">= new </span><span style="color: #0000BB">Imagick</span><span style="color: #007700">(</span><span style="color: #DD0000">'image.jpg'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// If 0 is provided as a width or height parameter,<br />// aspect ratio is maintained<br /></span><span style="color: #0000BB">$image</span><span style="color: #007700">-></span><span style="color: #0000BB">thumbnailImage</span><span style="color: #007700">(</span><span style="color: #0000BB">100</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">$image</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> Using SPL and other OO features supported in Imagick, it can be simple to resize all files in a directory (useful for batch resizing large digital camera images to be web viewable). Here we use resize, as we might want to retain certain meta-data: <div class="example"> <p><b>Example #2 Make a thumbnail of all JPG files in a directory</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br />$images </span><span style="color: #007700">= new </span><span style="color: #0000BB">Imagick</span><span style="color: #007700">(</span><span style="color: #0000BB">glob</span><span style="color: #007700">(</span><span style="color: #DD0000">'images/*.JPG'</span><span style="color: #007700">));<br /><br />foreach(</span><span style="color: #0000BB">$images </span><span style="color: #007700">as </span><span style="color: #0000BB">$image</span><span style="color: #007700">) {<br /><br /> </span><span style="color: #FF8000">// Providing 0 forces thumbnailImage to maintain aspect ratio<br /> </span><span style="color: #0000BB">$image</span><span style="color: #007700">-></span><span style="color: #0000BB">thumbnailImage</span><span style="color: #007700">(</span><span style="color: #0000BB">1024</span><span style="color: #007700">,</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br />}<br /><br /></span><span style="color: #0000BB">$images</span><span style="color: #007700">-></span><span style="color: #0000BB">writeImages</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?></span></span>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -