imagefile.php 23 KB

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