In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the operation method of Image in thinkphp". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the operation method of Image in thinkphp".
Image operation in stand-alone thinkphp3.2.3
Do not rely on any framework
In general, the GD library is installed.
If you need Imagick, please install https://pecl.php.net/package/imagick
Install the composer require whereof/think-image instantiation library $image = new\ whereof\ ThinkImage\ Image ()
GD library is used for image manipulation by default. If you need to use Imagick library, you need to change it to:
$image = new\ whereof\ ThinkImage\ Image (\ Think\ Image::IMAGE_IMAGICK); / / or use $image = new\ whereof\ ThinkImage\ Image ('Imagick'); image operation
Let's take a look at how to use the basic image manipulation function.
Open an image file
Suppose there is a 1.jpg file under the current entry file directory
Use the open method to open the image file for related operations:
$image =\ whereof\ ThinkImage\ Image (); $image- > open ('. / 1.jpg')
It can also be simplified to the following ways:
$image = new\ whereof\ ThinkImage\ Image (\ whereof\ ThinkImage\ Image::IMAGE_GD,'./1.jpg'); / / GD library / / or $image = new\ whereof\ ThinkImage\ Image (\ whereof\ ThinkImage\ Image::IMAGE_IMAGICK,'./1.jpg'); / / imagick library to obtain image information
You can get information about opening a picture, including image size, type, etc., for example:
$width = $image- > width (); / / return the width of the picture $height = $image- > height (); / / return the height of the picture $type = $image- > type (); / / return the type of picture $mime = $image- > mime (); / / return the mime type of the picture $size = $image- > size (); / / return the size array of the picture 0 picture width 1 picture height cropped picture
Use crop and save methods to complete the function of cropping pictures.
/ / crop the picture to 400x400 and save it as corp.jpg$image- > crop (400,400)-> save ('. / crop.jpg')
Support to start clipping from a certain coordinate, for example, starting from (100pc30) as follows:
/ / cut the picture to 400x400 and save it as corp.jpg$image- > crop (400,400 and 100jol 30)-> save ('. / crop.jpg'); generate thumbnails
Use the thumb method to generate thumbnails
/ / generate a thumbnail with a maximum of 150,150 according to the scale of the original image and save it as thumb.jpg$image- > thumb (150150)-> save ('. / thumb.jpg')
Other types of thumbnail generation can be supported, setting the following constants or corresponding numbers including\ whereof\ ThinkImage\ Image:
IMAGE_THUMB_SCALE = 1; / / proportional scaling type IMAGE_THUMB_FILLED = 2; / / scaled fill type IMAGE_THUMB_CENTER = 3; / / Center crop type IMAGE_THUMB_NORTHWEST = 4; / / upper left corner crop type IMAGE_THUMB_SOUTHEAST = 5; / / lower right corner crop type IMAGE_THUMB_FIXED = 6 / / fixed size zoom type center cropping / / generate a thumbnail centered to 150x150 and save as thumb.jpg$image- > thumb (150,150,\ whereof\ ThinkImage\ Image::IMAGE_THUMB_CENTER)-> save ('. / thumb.jpg'); upper left clip $image- > thumb (150,150,\ whereof\ ThinkImage\ Image::IMAGE_THUMB_NORTHWEST)-> save ('. / thumb.jpg') Zoom and fill $image- > thumb (150,150,\ whereof\ ThinkImage\ Image::IMAGE_THUMB_FILLED)-> save ('. / thumb.jpg'); fixed size $image- > thumb (150,150,\ whereof\ ThinkImage\ Image::IMAGE_THUMB_FIXED)-> save ('. / thumb.jpg'); add image watermark / / crop the picture to 440x440 and save it as corp.jpg$image- > crop (440,440)-> save ('. / crop.jpg') / / add a watermark to the cropped image (watermark file is located in. / logo.png), in the lower right corner, save as water.gif$image- > water ('. / logo.png')-> save ("water.gif"); / / add watermark to the original image and save it as water_o.gif (need to reopen the original image) $image- > open ('. / 1.jpg')-> water ('. / logo.png')-> save ("water_o.gif")
The second parameter of the water method indicates the location of the watermark. You can pass the constant of the following Think\ Imag class or the corresponding number:
IMAGE_WATER_NORTHWEST = 1; / / Top left watermark IMAGE_WATER_NORTH = 2; / / Top centering watermark IMAGE_WATER_NORTHEAST = 3; / / Top right centering watermark IMAGE_WATER_WEST = 4; / / left centering watermark IMAGE_WATER_CENTER = 5; / / centering watermark IMAGE_WATER_EAST = 6; / / right centering watermark IMAGE_WATER_SOUTHWEST = 7 / / bottom left corner watermark IMAGE_WATER_SOUTH = 8; / / bottom center watermark IMAGE_WATER_SOUTHEAST = 9; / / lower right corner watermark
For example:
$image- > open ('. / 1.jpg')-> water ('. / logo.png',\ whereof\ ThinkImage\ Image::IMAGE_WATER_NORTHWEST)-> save ("water.jpg")
You can also support the transparency of watermark images (0,100, default is 80), for example:
$image- > open ('. / 1.jpg')-> water ('. / logo.png',\ whereof\ ThinkImage\ Image::IMAGE_WATER_NORTHWEST,50)-> save ("water.jpg")
You can also add text watermarks to images (assuming that there is a 1.ttf font file in the same directory of the entry file), for example:
$image- > open ('. / 1.jpg')-> text ('ThinkPHP','./1.ttf',20,'#000000',\ whereof\ ThinkImage\ Image::IMAGE_WATER_SOUTHEAST)-> save ("new.jpg") Thank you for reading, the above is the content of "what is the operation method of Image in thinkphp". After the study of this article, I believe you have a deeper understanding of what the operation method of Image in thinkphp is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.