1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Images;
13
14 use ICanBoogie\I18n;
15 use ICanBoogie\Operation;
16
17 use Brickrouge\Element;
18
19
20
21 class ImageUpload extends \Icybee\Modules\Files\FileUpload
22 {
23 const THUMBNAIL_WIDTH = 64;
24 const THUMBNAIL_HEIGHT = 64;
25
26 static protected function add_assets(\Brickrouge\Document $document)
27 {
28 parent::add_assets($document);
29
30 $document->js->add(DIR . 'public/slimbox.js');
31 $document->css->add(DIR . 'public/slimbox.css');
32 $document->js->add(DIR . 'public/module.js');
33 $document->css->add(DIR . 'public/module.css');
34 }
35
36 protected function preview($path)
37 {
38 global $core;
39
40 $w = $this->w;
41 $h = $this->h;
42
43 $url = Operation::encode
44 (
45 'thumbnailer/get', array
46 (
47 'src' => $path,
48 'w' => $w,
49 'h' => $h,
50 'format' => 'jpeg',
51 'quality' => 90,
52 'background' => 'silver,white,medium',
53 'uniqid' => uniqid()
54 )
55 );
56
57 $img = new Element
58 (
59 'img', array
60 (
61 'src' => $url,
62 'width' => $w,
63 'height' => $h,
64 'alt' => ''
65 )
66 );
67
68 $repository = $core->config['repository.temp'];
69
70 if (strpos($path, $repository) === 0)
71 {
72 return $img;
73 }
74
75 return '<a href="' . $path . '&uniqid=' . uniqid() . '" rel="lightbox">' . $img . '</a>';
76 }
77
78 protected function details($path)
79 {
80 $path = $this['value'];
81
82 list($entry_width, $entry_height) = getimagesize($_SERVER['DOCUMENT_ROOT'] . $path);
83
84 $w = $entry_width;
85 $h = $entry_height;
86
87
88
89
90
91
92 $resized = false;
93
94 if (($w * $h) > (self::THUMBNAIL_WIDTH * self::THUMBNAIL_HEIGHT))
95 {
96 $resized = true;
97
98 $ratio = sqrt($w * $h);
99
100 $w = round($w / $ratio * self::THUMBNAIL_WIDTH);
101 $h = round($h / $ratio * self::THUMBNAIL_HEIGHT);
102 }
103
104 $this->w = $w;
105 $this->h = $h;
106
107
108
109
110
111 $details = array
112 (
113
114 I18n\t('Image size: {0}×{1}px', array($entry_width, $entry_height))
115 );
116
117 if (($entry_width != $w) || ($entry_height != $h))
118 {
119 $details[] = I18n\t('Display ratio: :ratio%', array(':ratio' => round(($w * $h) / ($entry_width * $entry_height) * 100)));
120 }
121 else
122 {
123 $details[] = I18n\t('Displayed as is');
124 }
125
126 $details[] = I18n\format_size(filesize($_SERVER['DOCUMENT_ROOT'] . $path));
127
128 return $details;
129 }
130 }