imagefile.php 23 KB

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