-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.php
More file actions
73 lines (64 loc) · 2.57 KB
/
demo.php
File metadata and controls
73 lines (64 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
require 'autoload.php';
// 源图片文件
$source = dirname(__FILE__).'/pic/source.jpg';
// 水印图片
$watermark = dirname(__FILE__).'/pic/watermark.png';
// 日志文件
$log_file = '/tmp/image-thumbnail.log';
// 缩略图配置(fit)
$config = new \Thumbnail\Config(500, 380);
$config->setThumbAdapterType(\Thumbnail\Config\ThumbAdapterType::FIT);
$config->setBgcolor('#FFCC33');
$config->setQuality(85);
$config->setWatermark($watermark);
$config->setWatermarkGravity(\Thumbnail\Config\WaterMarkGravity::NORTHEAST);
$config->setWatermarkGeometry('+5+35');
$config->setWatermarkOpacity(25);
$config->setLogFile($log_file);
// 缩略图处理类(ImageMagick)
$imagemagick_handler = \Thumbnail\Factory::make(\Thumbnail\Type::IMAGEMAGICK, $config);
$thumb = dirname(__FILE__).'/pic/imagemagick_fit_thumb.jpg';
$response = $imagemagick_handler->create($source, $thumb);
echo 'success='.$response->success().PHP_EOL;
if(!$response->success()){
echo 'error='.$response->errMsg().PHP_EOL;
}
echo $response->thumb().PHP_EOL.PHP_EOL;
// 缩略图处理类(GD库)
$gd_handler = \Thumbnail\Factory::make(\Thumbnail\Type::GD, $config);
$thumb = dirname(__FILE__).'/pic/gd_fit_thumb.jpg';
$response = $gd_handler->create($source, $thumb);
echo 'success='.$response->success().PHP_EOL;
if(!$response->success()){
echo 'error='.$response->errMsg().PHP_EOL;
}
echo $response->thumb().PHP_EOL.PHP_EOL;
// 缩略图配置(crop)
$config = new \Thumbnail\Config(400, 200);
$config->setThumbAdapterType(\Thumbnail\Config\ThumbAdapterType::CROP);
$config->setCropPosition(\Thumbnail\Config\CropPosition::MM);
$config->setQuality(85);
$config->setWatermark($watermark);
$config->setWatermarkGravity(\Thumbnail\Config\WaterMarkGravity::NORTHEAST);
$config->setWatermarkGeometry('+5+5');
$config->setWatermarkOpacity(35);
$config->setLogFile($log_file);
// 缩略图处理类(ImageMagick)
$imagemagick_handler = \Thumbnail\Factory::make(\Thumbnail\Type::IMAGEMAGICK, $config);
$thumb = dirname(__FILE__).'/pic/imagemagick_crop_thumb.jpg';
$response = $imagemagick_handler->create($source, $thumb);
echo 'success='.$response->success().PHP_EOL;
if(!$response->success()){
echo 'error='.$response->errMsg().PHP_EOL;
}
echo $response->thumb().PHP_EOL.PHP_EOL;
// 缩略图处理类(GD库)
$gd_handler = \Thumbnail\Factory::make(\Thumbnail\Type::GD, $config);
$thumb = dirname(__FILE__).'/pic/gd_crop_thumb.jpg';
$response = $gd_handler->create($source, $thumb);
echo 'success='.$response->success().PHP_EOL;
if(!$response->success()){
echo 'error='.$response->errMsg().PHP_EOL;
}
echo $response->thumb().PHP_EOL.PHP_EOL;