imagefile.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Abstraction for an image file
  18. *
  19. * @category Image
  20. * @package GNUsocial
  21. *
  22. * @author Evan Prodromou <evan@status.net>
  23. * @author Zach Copley <zach@status.net>
  24. * @author Mikael Nordfeldth <mmn@hethane.se>
  25. * @author Miguel Dantas <biodantasgs@gmail.com>
  26. * @author Diogo Cordeiro <diogo@fc.up.pt>
  27. * @copyright 2008, 2019-2020 Free Software Foundation http://fsf.org
  28. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  29. */
  30. defined('GNUSOCIAL') || die();
  31. use Intervention\Image\ImageManagerStatic as Image;
  32. /**
  33. * A wrapper on uploaded images
  34. *
  35. * Makes it slightly easier to accept an image file from upload.
  36. *
  37. * @category Image
  38. * @package GNUsocial
  39. *
  40. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  41. * @author Evan Prodromou <evan@status.net>
  42. * @author Zach Copley <zach@status.net>
  43. *
  44. * @see https://www.gnu.org/software/social/
  45. */
  46. class ImageFile extends MediaFile
  47. {
  48. public $widgetOpts;
  49. public $scoped;
  50. public $filehash;
  51. public $type;
  52. public $height;
  53. public $width;
  54. public $rotate = 0; // degrees to rotate for properly oriented image (extrapolated from EXIF etc.)
  55. public $animated; // Animated image? (has more than 1 frame). null means untested
  56. public $mimetype; // The _ImageFile_ mimetype, _not_ the originating File object
  57. /**
  58. * ImageFile constructor.
  59. *
  60. * @param int|null $id The DB id of the file. Int if known, null if not.
  61. * If null, it searches for it. If -1, it skips all DB
  62. * interactions (useful for temporary objects)
  63. * @param string $filepath The path of the file this media refers to. Required
  64. * @param string|null $filehash The hash of the file, if known. Optional
  65. * @param string|null $fileurl
  66. * @throws ClientException
  67. * @throws NoResultException
  68. * @throws ServerException
  69. * @throws UnsupportedMediaException
  70. */
  71. public function __construct(string $filepath, ?int $id = null, ?string $filehash = null, ?string $fileurl = null)
  72. {
  73. $old_limit = ini_set('memory_limit', common_config('attachments', 'memory_limit'));
  74. // These do not have to be the same as fileRecord->filename for example,
  75. // since we may have generated an image source file from something else!
  76. $this->filepath = $filepath;
  77. $this->filename = basename($filepath);
  78. $img = Image::make($this->filepath);
  79. $this->mimetype = $img->mime();
  80. $cmp = function ($obj, $type) {
  81. if ($obj->mimetype == image_type_to_mime_type($type)) {
  82. $obj->type = $type;
  83. return true;
  84. }
  85. return false;
  86. };
  87. if (!(($cmp($this, IMAGETYPE_GIF) && function_exists('imagecreatefromgif')) ||
  88. ($cmp($this, IMAGETYPE_JPEG) && function_exists('imagecreatefromjpeg')) ||
  89. ($cmp($this, IMAGETYPE_BMP) && function_exists('imagecreatefrombmp')) ||
  90. ($cmp($this, IMAGETYPE_WBMP) && function_exists('imagecreatefromwbmp')) ||
  91. ($cmp($this, IMAGETYPE_XBM) && function_exists('imagecreatefromxbm')) ||
  92. ($cmp($this, IMAGETYPE_PNG) && function_exists('imagecreatefrompng')) ||
  93. ($cmp($this, IMAGETYPE_WEBP) && function_exists('imagecreatefromwebp'))
  94. )
  95. ) {
  96. common_debug("Mimetype '{$this->mimetype}' was not recognized as a supported format");
  97. // TRANS: Exception thrown when trying to upload an unsupported image file format.
  98. throw new UnsupportedMediaException(_m('Unsupported image format.'), $this->filepath);
  99. }
  100. $this->width = $img->width();
  101. $this->height = $img->height();
  102. parent::__construct(
  103. $this->mimetype,
  104. $filepath,
  105. $filehash,
  106. $id,
  107. $fileurl
  108. );
  109. if ($this->type === IMAGETYPE_JPEG) {
  110. // Orientation value to rotate thumbnails properly
  111. $exif = @$img->exif();
  112. if (is_array($exif) && isset($exif['Orientation'])) {
  113. switch ((int)($exif['Orientation'])) {
  114. case 1: // top is top
  115. $this->rotate = 0;
  116. break;
  117. case 3: // top is bottom
  118. $this->rotate = 180;
  119. break;
  120. case 6: // top is right
  121. $this->rotate = -90;
  122. break;
  123. case 8: // top is left
  124. $this->rotate = 90;
  125. break;
  126. }
  127. // If we ever write this back, Orientation should be set to '1'
  128. }
  129. } elseif ($this->type === IMAGETYPE_GIF) {
  130. $this->animated = $this->isAnimatedGif();
  131. }
  132. Event::handle('FillImageFileMetadata', [$this]);
  133. $img->destroy();
  134. ini_set('memory_limit', $old_limit); // Restore the old memory limit
  135. }
  136. /**
  137. * Shortcut method to get an ImageFile from a File
  138. *
  139. * @param File $file
  140. * @return ImageFile
  141. * @throws ClientException
  142. * @throws FileNotFoundException
  143. * @throws NoResultException
  144. * @throws ServerException
  145. * @throws UnsupportedMediaException
  146. */
  147. public static function fromFileObject(File $file)
  148. {
  149. $media = common_get_mime_media($file->mimetype);
  150. // And we'll only consider it an image if it has such a media type
  151. if ($media !== 'image') {
  152. throw new UnsupportedMediaException(_m('Unsupported media format.'), $file->getPath());
  153. }
  154. $filepath = $file->getPath();
  155. return new self($filepath, $file->getID(), $file->filehash);
  156. }
  157. public function getPath()
  158. {
  159. if (!file_exists($this->filepath)) {
  160. throw new FileNotFoundException($this->filepath);
  161. }
  162. return $this->filepath;
  163. }
  164. /**
  165. * Process a file upload
  166. *
  167. * Uses MediaFile's `fromUpload` to do the majority of the work
  168. * and ensures the uploaded file is in fact an image.
  169. *
  170. * @param string $param
  171. * @param null|Profile $scoped
  172. *
  173. * @return ImageFile
  174. * @throws NoResultException
  175. * @throws NoUploadedMediaException
  176. * @throws ServerException
  177. * @throws UnsupportedMediaException
  178. * @throws UseFileAsThumbnailException
  179. *
  180. * @throws ClientException
  181. */
  182. public static function fromUpload(string $param = 'upload', ?Profile $scoped = null): self
  183. {
  184. $mediafile = parent::fromUpload($param, $scoped);
  185. if ($mediafile instanceof self) {
  186. return $mediafile;
  187. } else {
  188. $mediafile->delete();
  189. // We can conclude that we have failed to get the MIME type
  190. // TRANS: Client exception thrown trying to upload an invalid image type.
  191. // TRANS: %s is the file type that was denied
  192. $hint = sprintf(_m('"%s" is not a supported file type on this server. ' .
  193. 'Try using another image format.'), $mediafile->mimetype);
  194. throw new ClientException($hint);
  195. }
  196. }
  197. /**
  198. * Create a new ImageFile object from an url
  199. *
  200. * Uses MediaFile's `fromUrl` to do the majority of the work
  201. * and ensures the uploaded file is in fact an image.
  202. *
  203. * @param string $url Remote image URL
  204. * @param Profile|null $scoped
  205. * @param string|null $name
  206. * @param int|null $file_id same as in this class constructor
  207. * @return ImageFile
  208. * @throws ClientException
  209. * @throws HTTP_Request2_Exception
  210. * @throws InvalidFilenameException
  211. * @throws NoResultException
  212. * @throws ServerException
  213. * @throws UnsupportedMediaException
  214. * @throws UseFileAsThumbnailException
  215. */
  216. public static function fromUrl(string $url, ?Profile $scoped = null, ?string $name = null, ?int $file_id = null): self
  217. {
  218. $mediafile = parent::fromUrl($url, $scoped, $name, $file_id);
  219. if ($mediafile instanceof self) {
  220. return $mediafile;
  221. } else {
  222. $mediafile->delete();
  223. // We can conclude that we have failed to get the MIME type
  224. // TRANS: Client exception thrown trying to upload an invalid image type.
  225. // TRANS: %s is the file type that was denied
  226. $hint = sprintf(_m('"%s" is not a supported file type on this server. ' .
  227. 'Try using another image format.'), $mediafile->mimetype);
  228. throw new ClientException($hint);
  229. }
  230. }
  231. /**
  232. * Several obscure file types should be normalized to WebP on resize.
  233. *
  234. * Keeps only GIF (if animated) and WebP formats
  235. *
  236. * @return int
  237. */
  238. public function preferredType()
  239. {
  240. if ($this->type == IMAGETYPE_GIF && $this->animated) {
  241. return $this->type;
  242. }
  243. return IMAGETYPE_WEBP;
  244. }
  245. /**
  246. * Copy the image file to the given destination.
  247. *
  248. * This function may modify the resulting file. Please use the
  249. * returned ImageFile object to read metadata (width, height etc.)
  250. *
  251. * @param string $outpath
  252. *
  253. * @return ImageFile the image stored at target path
  254. * @throws NoResultException
  255. * @throws ServerException
  256. * @throws UnsupportedMediaException
  257. * @throws UseFileAsThumbnailException
  258. *
  259. * @throws ClientException
  260. */
  261. public function copyTo($outpath)
  262. {
  263. return new self($this->resizeTo($outpath));
  264. }
  265. /**
  266. * Create and save a thumbnail image.
  267. *
  268. * @param string $outpath
  269. * @param array $box width, height, boundary box (x,y,w,h) defaults to full image
  270. *
  271. * @return string full local filesystem filename
  272. * @return string full local filesystem filename
  273. * @throws UnsupportedMediaException
  274. * @throws UseFileAsThumbnailException
  275. *
  276. */
  277. public function resizeTo($outpath, array $box = [])
  278. {
  279. $box['width'] = isset($box['width']) ? (int)($box['width']) : $this->width;
  280. $box['height'] = isset($box['height']) ? (int)($box['height']) : $this->height;
  281. $box['x'] = isset($box['x']) ? (int)($box['x']) : 0;
  282. $box['y'] = isset($box['y']) ? (int)($box['y']) : 0;
  283. $box['w'] = isset($box['w']) ? (int)($box['w']) : $this->width;
  284. $box['h'] = isset($box['h']) ? (int)($box['h']) : $this->height;
  285. if (!file_exists($this->filepath)) {
  286. // TRANS: Exception thrown during resize when image has been registered as present,
  287. // but is no longer there.
  288. throw new FileNotFoundException($this->filepath);
  289. }
  290. // Don't rotate/crop/scale if it isn't necessary
  291. if ($box['width'] === $this->width
  292. && $box['height'] === $this->height
  293. && $box['x'] === 0
  294. && $box['y'] === 0
  295. && $box['w'] === $this->width
  296. && $box['h'] === $this->height
  297. && $this->type === $this->preferredType()) {
  298. if (abs($this->rotate) == 90) {
  299. // Box is rotated 90 degrees in either direction,
  300. // so we have to redefine x to y and vice versa.
  301. $tmp = $box['width'];
  302. $box['width'] = $box['height'];
  303. $box['height'] = $tmp;
  304. $tmp = $box['x'];
  305. $box['x'] = $box['y'];
  306. $box['y'] = $tmp;
  307. $tmp = $box['w'];
  308. $box['w'] = $box['h'];
  309. $box['h'] = $tmp;
  310. }
  311. }
  312. $this->height = $box['h'];
  313. $this->width = $box['w'];
  314. if (Event::handle('StartResizeImageFile', [$this, $outpath, $box])) {
  315. $outpath = $this->resizeToFile($outpath, $box);
  316. }
  317. if (!file_exists($outpath)) {
  318. if ($this->fileRecord instanceof File) {
  319. throw new UseFileAsThumbnailException($this->fileRecord);
  320. } else {
  321. throw new UnsupportedMediaException('No local File object exists for ImageFile.');
  322. }
  323. }
  324. return $outpath;
  325. }
  326. /**
  327. * Resizes a file. If $box is omitted, the size is not changed, but this is still useful,
  328. * because it will reencode the image in the `self::prefferedType()` format. This only
  329. * applies henceforward, not retroactively
  330. *
  331. * Increases the 'memory_limit' to the one in the 'attachments' section in the config, to
  332. * enable the handling of bigger images, which can cause a peak of memory consumption, while
  333. * encoding
  334. *
  335. * @param $outpath
  336. * @param array $box
  337. *
  338. * @throws Exception
  339. */
  340. protected function resizeToFile(string $outpath, array $box): string
  341. {
  342. $old_limit = ini_set('memory_limit', common_config('attachments', 'memory_limit'));
  343. try {
  344. $img = Image::make($this->filepath);
  345. } catch (Exception $e) {
  346. common_log(LOG_ERR, __METHOD__ . ' encountered exception: ' . print_r($e, true));
  347. // TRANS: Exception thrown when trying to resize an unknown file type.
  348. throw new Exception(_m('Unknown file type'));
  349. }
  350. if ($this->filepath === $outpath) {
  351. @unlink($outpath);
  352. }
  353. if ($this->rotate != 0) {
  354. $img = $img->orientate();
  355. }
  356. $img->fit(
  357. $box['width'],
  358. $box['height'],
  359. function ($constraint) {
  360. if (common_config('attachments', 'upscale') !== true) {
  361. $constraint->upsize(); // Prevent upscaling
  362. }
  363. }
  364. );
  365. // Ensure we save in the correct format and allow customization based on type
  366. $type = $this->preferredType();
  367. switch ($type) {
  368. case IMAGETYPE_WEBP:
  369. $img->save($outpath, 100, 'webp');
  370. break;
  371. case IMAGETYPE_GIF:
  372. $img->save($outpath, 100, 'gif');
  373. break;
  374. default:
  375. // TRANS: Exception thrown when trying resize an unknown file type.
  376. throw new Exception(_m('Unknown file type'));
  377. }
  378. $img->destroy();
  379. ini_set('memory_limit', $old_limit); // Restore the old memory limit
  380. return $outpath;
  381. }
  382. public function scaleToFit($maxWidth = null, $maxHeight = null, $crop = null)
  383. {
  384. return self::getScalingValues(
  385. $this->width,
  386. $this->height,
  387. $maxWidth,
  388. $maxHeight,
  389. $crop,
  390. $this->rotate
  391. );
  392. }
  393. /**
  394. * Gets scaling values for images of various types. Cropping can be enabled.
  395. *
  396. * Values will scale _up_ to fit max values if cropping is enabled!
  397. * With cropping disabled, the max value of each axis will be respected.
  398. *
  399. * @param $width int Original width
  400. * @param $height int Original height
  401. * @param $maxW int Resulting max width
  402. * @param $maxH int Resulting max height
  403. * @param $crop int Crop to the size (not preserving aspect ratio)
  404. * @param int $rotate
  405. *
  406. * @return array
  407. * @throws ServerException
  408. *
  409. */
  410. public static function getScalingValues(
  411. $width,
  412. $height,
  413. $maxW = null,
  414. $maxH = null,
  415. $crop = null,
  416. $rotate = 0
  417. ) {
  418. $maxW = $maxW ?: common_config('thumbnail', 'width');
  419. $maxH = $maxH ?: common_config('thumbnail', 'height');
  420. if ($maxW < 1 || ($maxH !== null && $maxH < 1)) {
  421. throw new ServerException('Bad parameters for ImageFile::getScalingValues');
  422. }
  423. if ($maxH === null) {
  424. // if maxH is null, we set maxH to equal maxW and enable crop
  425. $maxH = $maxW;
  426. $crop = true;
  427. }
  428. // Because GD doesn't understand EXIF orientation etc.
  429. if (abs($rotate) == 90) {
  430. $tmp = $width;
  431. $width = $height;
  432. $height = $tmp;
  433. }
  434. // Cropping data (for original image size). Default values, 0 and null,
  435. // imply no cropping and with preserved aspect ratio (per axis).
  436. $cx = 0; // crop x
  437. $cy = 0; // crop y
  438. $cw = null; // crop area width
  439. $ch = null; // crop area height
  440. if ($crop) {
  441. $s_ar = $width / $height;
  442. $t_ar = $maxW / $maxH;
  443. $rw = $maxW;
  444. $rh = $maxH;
  445. // Source aspect ratio differs from target, recalculate crop points!
  446. if ($s_ar > $t_ar) {
  447. $cx = floor($width / 2 - $height * $t_ar / 2);
  448. $cw = ceil($height * $t_ar);
  449. } elseif ($s_ar < $t_ar) {
  450. $cy = floor($height / 2 - $width / $t_ar / 2);
  451. $ch = ceil($width / $t_ar);
  452. }
  453. } else {
  454. $rw = $maxW;
  455. $rh = ceil($height * $rw / $width);
  456. // Scaling caused too large height, decrease to max accepted value
  457. if ($rh > $maxH) {
  458. $rh = $maxH;
  459. $rw = ceil($width * $rh / $height);
  460. }
  461. }
  462. return [(int)$rw, (int)$rh,
  463. (int)$cx, (int)$cy,
  464. is_null($cw) ? $width : (int)$cw,
  465. is_null($ch) ? $height : (int)$ch];
  466. }
  467. /**
  468. * Animated GIF test, courtesy of frank at huddler dot com et al:
  469. * http://php.net/manual/en/function.imagecreatefromgif.php#104473
  470. * Modified so avoid landing inside of a header (and thus not matching our regexp).
  471. */
  472. protected function isAnimatedGif()
  473. {
  474. if (!($fh = @fopen($this->filepath, 'rb'))) {
  475. return false;
  476. }
  477. $count = 0;
  478. //an animated gif contains multiple "frames", with each frame having a
  479. //header made up of:
  480. // * a static 4-byte sequence (\x00\x21\xF9\x04)
  481. // * 4 variable bytes
  482. // * a static 2-byte sequence (\x00\x2C)
  483. // In total the header is maximum 10 bytes.
  484. // We read through the file til we reach the end of the file, or we've found
  485. // at least 2 frame headers
  486. while (!feof($fh) && $count < 2) {
  487. $chunk = fread($fh, 1024 * 100); //read 100kb at a time
  488. $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00\x2C#s', $chunk, $matches);
  489. // rewind in case we ended up in the middle of the header, but avoid
  490. // infinite loop (i.e. don't rewind if we're already in the end).
  491. if (!feof($fh) && ftell($fh) >= 9) {
  492. fseek($fh, -9, SEEK_CUR);
  493. }
  494. }
  495. fclose($fh);
  496. return $count >= 1; // number of animated frames apart from the original image
  497. }
  498. /**
  499. * @param $width
  500. * @param $height
  501. * @param $crop
  502. * @param false $upscale
  503. * @return File_thumbnail
  504. * @throws ClientException
  505. * @throws FileNotFoundException
  506. * @throws FileNotStoredLocallyException
  507. * @throws InvalidFilenameException
  508. * @throws ServerException
  509. * @throws UnsupportedMediaException
  510. * @throws UseFileAsThumbnailException
  511. */
  512. public function getFileThumbnail($width = null, $height = null, $crop = null, $upscale = false)
  513. {
  514. if (!$this->fileRecord instanceof File) {
  515. throw new ServerException('No File object attached to this ImageFile object.');
  516. }
  517. // Throws FileNotFoundException or FileNotStoredLocallyException
  518. $this->filepath = $this->fileRecord->getFileOrThumbnailPath();
  519. $filename = basename($this->filepath);
  520. if ($width === null) {
  521. $width = common_config('thumbnail', 'width');
  522. $height = common_config('thumbnail', 'height');
  523. $crop = common_config('thumbnail', 'crop');
  524. }
  525. if (!$upscale) {
  526. if ($width > $this->width) {
  527. $width = $this->width;
  528. }
  529. if (!is_null($height) && $height > $this->height) {
  530. $height = $this->height;
  531. }
  532. }
  533. if ($height === null) {
  534. $height = $width;
  535. $crop = true;
  536. }
  537. // Get proper aspect ratio width and height before lookup
  538. // We have to do it through an ImageFile object because of orientation etc.
  539. // Only other solution would've been to rotate + rewrite uploaded files
  540. // which we don't want to do because we like original, untouched data!
  541. list($width, $height, $x, $y, $w, $h) = $this->scaleToFit($width, $height, $crop);
  542. $thumb = File_thumbnail::pkeyGet([
  543. 'file_id' => $this->fileRecord->getID(),
  544. 'width' => $width,
  545. 'height' => $height,
  546. ]);
  547. if ($thumb instanceof File_thumbnail) {
  548. $this->height = $height;
  549. $this->width = $width;
  550. return $thumb;
  551. }
  552. $type = $this->preferredType();
  553. $ext = image_type_to_extension($type, true);
  554. // Decoding returns null if the file is in the old format
  555. $filename = MediaFile::decodeFilename(basename($this->filepath));
  556. // Encoding null makes the file use 'untitled', and also replaces the extension
  557. $outfilename = MediaFile::encodeFilename($filename, $this->filehash, $ext);
  558. // The boundary box for our resizing
  559. $box = [
  560. 'width' => $width, 'height' => $height,
  561. 'x' => $x, 'y' => $y,
  562. 'w' => $w, 'h' => $h,
  563. ];
  564. $outpath = File_thumbnail::path(
  565. "thumb-{$this->fileRecord->id}-{$box['width']}x{$box['height']}-{$outfilename}"
  566. );
  567. // Doublecheck that parameters are sane and integers.
  568. if ($box['width'] < 1 || $box['width'] > common_config('thumbnail', 'maxsize')
  569. || $box['height'] < 1 || $box['height'] > common_config('thumbnail', 'maxsize')
  570. || $box['w'] < 1 || $box['x'] >= $this->width
  571. || $box['h'] < 1 || $box['y'] >= $this->height) {
  572. // Fail on bad width parameter. If this occurs, it's due to algorithm in ImageFile->scaleToFit
  573. common_debug("Boundary box parameters for resize of {$this->filepath} : " . var_export($box, true));
  574. throw new ServerException('Bad thumbnail size parameters.');
  575. }
  576. common_debug(sprintf(
  577. 'Generating a thumbnail of File id=%u of size %ux%u',
  578. $this->fileRecord->getID(),
  579. $width,
  580. $height
  581. ));
  582. $this->height = $box['height'];
  583. $this->width = $box['width'];
  584. // Perform resize and store into file
  585. $outpath = $this->resizeTo($outpath, $box);
  586. $outname = basename($outpath);
  587. return File_thumbnail::saveThumbnail(
  588. $this->fileRecord->getID(),
  589. $this->fileRecord->getUrl(false),
  590. $width,
  591. $height,
  592. $outname
  593. );
  594. }
  595. }