ProfilePic.php 683 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace app\models;
  3. //Import image magic (lazy load)
  4. use imagick;
  5. class ProfilePic extends \lithium\data\Model {
  6. //Where we are going to store the files in mongoDB
  7. protected $_meta = array('source' => 'fs.files');
  8. //Overriding save to do the thumbnailing :)
  9. public function save($entity, $data, array $options = array())
  10. {
  11. //Create a new imagemagick object from the uploaded file
  12. $im = new Imagick($data['file']);
  13. //Create a thumbnail of the file, then store it in the "thumbnail" object
  14. $data['thumbnail'] = $im->thumbnailImage(200, null);
  15. //Pass the changes off to the original save method.
  16. return parent::save($entity, $data, $options);
  17. }
  18. }
  19. ?>