3 * @file src/Object/Photo.php
4 * @brief This file contains the Photo class for image processing
6 namespace Friendica\Object;
9 use Friendica\Core\Cache;
10 use Friendica\Core\Config;
11 use Friendica\Core\System;
12 use Friendica\Database\DBM;
18 require_once "include/photos.php";
21 * Class to handle Photos
28 * Put back gd stuff, not everybody have Imagick
38 * @brief supported mimetypes and corresponding file extensions
41 public static function supportedTypes()
43 if (class_exists('Imagick')) {
44 // Imagick::queryFormats won't help us a lot there...
45 // At least, not yet, other parts of friendica uses this array
47 'image/jpeg' => 'jpg',
53 $t['image/jpeg'] ='jpg';
54 if (imagetypes() & IMG_PNG) {
55 $t['image/png'] = 'png';
64 * @param object $data data
65 * @param boolean $type optional, default null
68 public function __construct($data, $type = null)
70 $this->imagick = class_exists('Imagick');
71 $this->types = static::supportedTypes();
72 if (!array_key_exists($type, $this->types)) {
77 if ($this->isImagick() && $this->loadData($data)) {
80 // Failed to load with Imagick, fallback
81 $this->imagick = false;
83 return $this->loadData($data);
90 public function __destruct()
93 if ($this->isImagick()) {
94 $this->image->clear();
95 $this->image->destroy();
98 if (is_resource($this->image)) {
99 imagedestroy($this->image);
107 public function isImagick()
109 return $this->imagick;
113 * @brief Maps Mime types to Imagick formats
114 * @return arr With with image formats (mime type as key)
116 public static function getFormatsMap()
119 'image/jpeg' => 'JPG',
120 'image/png' => 'PNG',
127 * @param object $data data
130 private function loadData($data)
132 if ($this->isImagick()) {
133 $this->image = new Imagick();
135 $this->image->readImageBlob($data);
136 } catch (Exception $e) {
137 // Imagick couldn't use the data
142 * Setup the image to the format it will be saved to
144 $map = self::getFormatsMap();
145 $format = $map[$type];
146 $this->image->setFormat($format);
148 // Always coalesce, if it is not a multi-frame image it won't hurt anyway
149 $this->image = $this->image->coalesceImages();
152 * setup the compression here, so we'll do it only once
154 switch ($this->getType()) {
156 $quality = Config::get('system', 'png_quality');
157 if ((! $quality) || ($quality > 9)) {
158 $quality = PNG_QUALITY;
161 * From http://www.imagemagick.org/script/command-line-options.php#quality:
163 * 'For the MNG and PNG image formats, the quality value sets
164 * the zlib compression level (quality / 10) and filter-type (quality % 10).
165 * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering,
166 * unless the image has a color map, in which case it means compression level 7 with no PNG filtering'
168 $quality = $quality * 10;
169 $this->image->setCompressionQuality($quality);
172 $quality = Config::get('system', 'jpeg_quality');
173 if ((! $quality) || ($quality > 100)) {
174 $quality = JPEG_QUALITY;
176 $this->image->setCompressionQuality($quality);
179 // The 'width' and 'height' properties are only used by non-Imagick routines.
180 $this->width = $this->image->getImageWidth();
181 $this->height = $this->image->getImageHeight();
187 $this->valid = false;
188 $this->image = @imagecreatefromstring($data);
189 if ($this->image !== false) {
190 $this->width = imagesx($this->image);
191 $this->height = imagesy($this->image);
193 imagealphablending($this->image, false);
194 imagesavealpha($this->image, true);
205 public function isValid()
207 if ($this->isImagick()) {
208 return ($this->image !== false);
216 public function getWidth()
218 if (!$this->isValid()) {
222 if ($this->isImagick()) {
223 return $this->image->getImageWidth();
231 public function getHeight()
233 if (!$this->isValid()) {
237 if ($this->isImagick()) {
238 return $this->image->getImageHeight();
240 return $this->height;
246 public function getImage()
248 if (!$this->isValid()) {
252 if ($this->isImagick()) {
254 $this->image = $this->image->deconstructImages();
263 public function getType()
265 if (!$this->isValid()) {
275 public function getExt()
277 if (!$this->isValid()) {
281 return $this->types[$this->getType()];
285 * @param integer $max max dimension
288 public function scaleImage($max)
290 if (!$this->isValid()) {
294 $width = $this->getWidth();
295 $height = $this->getHeight();
297 $dest_width = $dest_height = 0;
299 if ((! $width)|| (! $height)) {
303 if ($width > $max && $height > $max) {
304 // very tall image (greater than 16:9)
305 // constrain the width - let the height float.
307 if ((($height * 9) / 16) > $width) {
309 $dest_height = intval(($height * $max) / $width);
310 } elseif ($width > $height) {
311 // else constrain both dimensions
313 $dest_height = intval(($height * $max) / $width);
315 $dest_width = intval(($width * $max) / $height);
321 $dest_height = intval(($height * $max) / $width);
323 if ($height > $max) {
324 // very tall image (greater than 16:9)
325 // but width is OK - don't do anything
327 if ((($height * 9) / 16) > $width) {
328 $dest_width = $width;
329 $dest_height = $height;
331 $dest_width = intval(($width * $max) / $height);
335 $dest_width = $width;
336 $dest_height = $height;
342 if ($this->isImagick()) {
344 * If it is not animated, there will be only one iteration here,
345 * so don't bother checking
347 // Don't forget to go back to the first frame
348 $this->image->setFirstIterator();
350 // FIXME - implement horizantal bias for scaling as in followin GD functions
351 // to allow very tall images to be constrained only horizontally.
353 $this->image->scaleImage($dest_width, $dest_height);
354 } while ($this->image->nextImage());
356 // These may not be necessary any more
357 $this->width = $this->image->getImageWidth();
358 $this->height = $this->image->getImageHeight();
364 $dest = imagecreatetruecolor($dest_width, $dest_height);
365 imagealphablending($dest, false);
366 imagesavealpha($dest, true);
367 if ($this->type=='image/png') {
368 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
370 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
372 imagedestroy($this->image);
374 $this->image = $dest;
375 $this->width = imagesx($this->image);
376 $this->height = imagesy($this->image);
380 * @param integer $degrees degrees to rotate image
383 public function rotate($degrees)
385 if (!$this->isValid()) {
389 if ($this->isImagick()) {
390 $this->image->setFirstIterator();
392 $this->image->rotateImage(new ImagickPixel(), -$degrees); // ImageMagick rotates in the opposite direction of imagerotate()
393 } while ($this->image->nextImage());
397 // if script dies at this point check memory_limit setting in php.ini
398 $this->image = imagerotate($this->image, $degrees, 0);
399 $this->width = imagesx($this->image);
400 $this->height = imagesy($this->image);
404 * @param boolean $horiz optional, default true
405 * @param boolean $vert optional, default false
408 public function flip($horiz = true, $vert = false)
410 if (!$this->isValid()) {
414 if ($this->isImagick()) {
415 $this->image->setFirstIterator();
418 $this->image->flipImage();
421 $this->image->flopImage();
423 } while ($this->image->nextImage());
427 $w = imagesx($this->image);
428 $h = imagesy($this->image);
429 $flipped = imagecreate($w, $h);
431 for ($x = 0; $x < $w; $x++) {
432 imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h);
436 for ($y = 0; $y < $h; $y++) {
437 imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1);
440 $this->image = $flipped;
444 * @param string $filename filename
447 public function orient($filename)
449 if ($this->isImagick()) {
450 // based off comment on http://php.net/manual/en/imagick.getimageorientation.php
451 $orientation = $this->image->getImageOrientation();
452 switch ($orientation) {
453 case Imagick::ORIENTATION_BOTTOMRIGHT:
454 $this->image->rotateimage("#000", 180);
456 case Imagick::ORIENTATION_RIGHTTOP:
457 $this->image->rotateimage("#000", 90);
459 case Imagick::ORIENTATION_LEFTBOTTOM:
460 $this->image->rotateimage("#000", -90);
464 $this->image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
467 // based off comment on http://php.net/manual/en/function.imagerotate.php
469 if (!$this->isValid()) {
473 if ((!function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) {
477 $exif = @exif_read_data($filename, null, true);
482 $ort = $exif['IFD0']['Orientation'];
488 case 2: // horizontal flip
492 case 3: // 180 rotate left
496 case 4: // vertical flip
497 $this->flip(false, true);
500 case 5: // vertical flip + 90 rotate right
501 $this->flip(false, true);
505 case 6: // 90 rotate right
509 case 7: // horizontal flip + 90 rotate right
514 case 8: // 90 rotate left
519 // logger('exif: ' . print_r($exif,true));
524 * @param integer $min minimum dimension
527 public function scaleImageUp($min)
529 if (!$this->isValid()) {
533 $width = $this->getWidth();
534 $height = $this->getHeight();
536 $dest_width = $dest_height = 0;
538 if ((!$width)|| (!$height)) {
542 if ($width < $min && $height < $min) {
543 if ($width > $height) {
545 $dest_height = intval(($height * $min) / $width);
547 $dest_width = intval(($width * $min) / $height);
553 $dest_height = intval(($height * $min) / $width);
555 if ($height < $min) {
556 $dest_width = intval(($width * $min) / $height);
559 $dest_width = $width;
560 $dest_height = $height;
565 if ($this->isImagick()) {
566 return $this->scaleImage($dest_width, $dest_height);
569 $dest = imagecreatetruecolor($dest_width, $dest_height);
570 imagealphablending($dest, false);
571 imagesavealpha($dest, true);
572 if ($this->type=='image/png') {
573 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
575 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
577 imagedestroy($this->image);
579 $this->image = $dest;
580 $this->width = imagesx($this->image);
581 $this->height = imagesy($this->image);
585 * @param integer $dim dimension
588 public function scaleImageSquare($dim)
590 if (!$this->isValid()) {
594 if ($this->isImagick()) {
595 $this->image->setFirstIterator();
597 $this->image->scaleImage($dim, $dim);
598 } while ($this->image->nextImage());
602 $dest = imagecreatetruecolor($dim, $dim);
603 imagealphablending($dest, false);
604 imagesavealpha($dest, true);
605 if ($this->type=='image/png') {
606 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
608 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height);
610 imagedestroy($this->image);
612 $this->image = $dest;
613 $this->width = imagesx($this->image);
614 $this->height = imagesy($this->image);
618 * @param integer $max maximum
619 * @param integer $x x coordinate
620 * @param integer $y y coordinate
621 * @param integer $w width
622 * @param integer $h height
625 public function cropImage($max, $x, $y, $w, $h)
627 if (!$this->isValid()) {
631 if ($this->isImagick()) {
632 $this->image->setFirstIterator();
634 $this->image->cropImage($w, $h, $x, $y);
636 * We need to remove the canva,
637 * or the image is not resized to the crop:
638 * http://php.net/manual/en/imagick.cropimage.php#97232
640 $this->image->setImagePage(0, 0, 0, 0);
641 } while ($this->image->nextImage());
642 return $this->scaleImage($max);
645 $dest = imagecreatetruecolor($max, $max);
646 imagealphablending($dest, false);
647 imagesavealpha($dest, true);
648 if ($this->type=='image/png') {
649 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
651 imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
653 imagedestroy($this->image);
655 $this->image = $dest;
656 $this->width = imagesx($this->image);
657 $this->height = imagesy($this->image);
661 * @param string $path file path
664 public function saveImage($path)
666 if (!$this->isValid()) {
670 $string = $this->imageString();
674 $stamp1 = microtime(true);
675 file_put_contents($path, $string);
676 $a->save_timestamp($stamp1, "file");
682 public function imageString()
684 if (!$this->isValid()) {
688 if ($this->isImagick()) {
690 $this->image = $this->image->deconstructImages();
691 $string = $this->image->getImagesBlob();
699 // Enable interlacing
700 imageinterlace($this->image, true);
702 switch ($this->getType()) {
704 $quality = Config::get('system', 'png_quality');
705 if ((!$quality) || ($quality > 9)) {
706 $quality = PNG_QUALITY;
708 imagepng($this->image, null, $quality);
711 $quality = Config::get('system', 'jpeg_quality');
712 if ((!$quality) || ($quality > 100)) {
713 $quality = JPEG_QUALITY;
715 imagejpeg($this->image, null, $quality);
717 $string = ob_get_contents();
724 * @param integer $uid uid
725 * @param integer $cid cid
726 * @param integer $rid rid
727 * @param string $filename filename
728 * @param string $album album name
729 * @param integer $scale scale
730 * @param integer $profile optional, default = 0
731 * @param string $allow_cid optional, default = ''
732 * @param string $allow_gid optional, default = ''
733 * @param string $deny_cid optional, default = ''
734 * @param string $deny_gid optional, default = ''
735 * @param string $desc optional, default = ''
738 public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '')
740 $r = dba::select('photo', array('guid'), array("`resource-id` = ? AND `guid` != ?", $rid, ''), array('limit' => 1));
741 if (DBM::is_result($r)) {
747 $x = dba::select('photo', array('id'), array('resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale), array('limit' => 1));
749 $fields = array('uid' => $uid, 'contact-id' => $cid, 'guid' => $guid, 'resource-id' => $rid, 'created' => datetime_convert(), 'edited' => datetime_convert(),
750 'filename' => basename($filename), 'type' => $this->getType(), 'album' => $album, 'height' => $this->getHeight(), 'width' => $this->getWidth(),
751 'datasize' => strlen($this->imageString()), 'data' => $this->imageString(), 'scale' => $scale, 'profile' => $profile,
752 'allow_cid' => $allow_cid, 'allow_gid' => $allow_gid, 'deny_cid' => $deny_cid, 'deny_gid' => $deny_gid, 'desc' => $desc);
754 if (DBM::is_result($x)) {
755 $r = dba::update('photo', $fields, array('id' => $x['id']));
757 $r = dba::insert('photo', $fields);
764 * Guess image mimetype from filename or from Content-Type header
766 * @param string $filename Image filename
767 * @param boolean $fromcurl Check Content-Type header from curl request
771 public static function guessImageType($filename, $fromcurl = false)
773 logger('Photo: guessImageType: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
778 $h = explode("\n", $a->get_curl_headers());
780 list($k,$v) = array_map("trim", explode(":", trim($l), 2));
783 if (array_key_exists('Content-Type', $headers))
784 $type = $headers['Content-Type'];
786 if (is_null($type)) {
787 // Guessing from extension? Isn't that... dangerous?
788 if (class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
790 * Well, this not much better,
791 * but at least it comes from the data inside the image,
792 * we won't be tricked by a manipulated extension
794 $image = new Imagick($filename);
795 $type = $image->getImageMimeType();
796 $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
798 $ext = pathinfo($filename, PATHINFO_EXTENSION);
799 $types = self::supportedTypes();
800 $type = "image/jpeg";
801 foreach ($types as $m => $e) {
808 logger('Photo: guessImageType: type='.$type, LOGGER_DEBUG);
813 * @param string $photo photo
814 * @param integer $uid user id
815 * @param integer $cid contact id
816 * @param boolean $quit_on_error optional, default false
819 public static function importProfilePhoto($photo, $uid, $cid, $quit_on_error = false)
823 array('resource-id'),
824 array('uid' => $uid, 'contact-id' => $cid, 'scale' => 4, 'album' => 'Contact Photos'),
828 if (DBM::is_result($r) && strlen($r['resource-id'])) {
829 $hash = $r['resource-id'];
831 $hash = photo_new_resource();
834 $photo_failure = false;
836 $filename = basename($photo);
837 $img_str = fetch_url($photo, true);
839 if ($quit_on_error && ($img_str == "")) {
843 $type = self::guessImageType($photo, true);
844 $img = new Photo($img_str, $type);
845 if ($img->isValid()) {
846 $img->scaleImageSquare(175);
848 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4);
851 $photo_failure = true;
854 $img->scaleImage(80);
856 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5);
859 $photo_failure = true;
862 $img->scaleImage(48);
864 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6);
867 $photo_failure = true;
870 $suffix = '?ts='.time();
872 $photo = System::baseUrl() . '/photo/' . $hash . '-4.' . $img->getExt() . $suffix;
873 $thumb = System::baseUrl() . '/photo/' . $hash . '-5.' . $img->getExt() . $suffix;
874 $micro = System::baseUrl() . '/photo/' . $hash . '-6.' . $img->getExt() . $suffix;
876 // Remove the cached photo
878 $basepath = $a->get_basepath();
880 if (is_dir($basepath."/photo")) {
881 $filename = $basepath.'/photo/'.$hash.'-4.'.$img->getExt();
882 if (file_exists($filename)) {
885 $filename = $basepath.'/photo/'.$hash.'-5.'.$img->getExt();
886 if (file_exists($filename)) {
889 $filename = $basepath.'/photo/'.$hash.'-6.'.$img->getExt();
890 if (file_exists($filename)) {
895 $photo_failure = true;
898 if ($photo_failure && $quit_on_error) {
902 if ($photo_failure) {
903 $photo = System::baseUrl() . '/images/person-175.jpg';
904 $thumb = System::baseUrl() . '/images/person-80.jpg';
905 $micro = System::baseUrl() . '/images/person-48.jpg';
908 return array($photo, $thumb, $micro);
912 * @param string $url url
915 public static function getInfoFromURL($url)
919 $data = Cache::get($url);
921 if (is_null($data) || !$data || !is_array($data)) {
922 $img_str = fetch_url($url, true, $redirects, 4);
923 $filesize = strlen($img_str);
925 if (function_exists("getimagesizefromstring")) {
926 $data = getimagesizefromstring($img_str);
928 $tempfile = tempnam(get_temppath(), "cache");
931 $stamp1 = microtime(true);
932 file_put_contents($tempfile, $img_str);
933 $a->save_timestamp($stamp1, "file");
935 $data = getimagesize($tempfile);
940 $data["size"] = $filesize;
943 Cache::set($url, $data);
950 * @param integer $width width
951 * @param integer $height height
952 * @param integer $max max
955 public static function scaleImageTo($width, $height, $max)
957 $dest_width = $dest_height = 0;
959 if ((!$width) || (!$height)) {
963 if ($width > $max && $height > $max) {
964 // very tall image (greater than 16:9)
965 // constrain the width - let the height float.
967 if ((($height * 9) / 16) > $width) {
969 $dest_height = intval(($height * $max) / $width);
970 } elseif ($width > $height) {
971 // else constrain both dimensions
973 $dest_height = intval(($height * $max) / $width);
975 $dest_width = intval(($width * $max) / $height);
981 $dest_height = intval(($height * $max) / $width);
983 if ($height > $max) {
984 // very tall image (greater than 16:9)
985 // but width is OK - don't do anything
987 if ((($height * 9) / 16) > $width) {
988 $dest_width = $width;
989 $dest_height = $height;
991 $dest_width = intval(($width * $max) / $height);
995 $dest_width = $width;
996 $dest_height = $height;
1000 return array("width" => $dest_width, "height" => $dest_height);
1004 * @brief This function is used by the fromgplus addon
1005 * @param object $a App
1006 * @param integer $uid user id
1007 * @param string $imagedata optional, default empty
1008 * @param string $url optional, default empty
1011 public static function storePhoto(App $a, $uid, $imagedata = "", $url = "")
1014 "SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
1015 WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1",
1019 if (!DBM::is_result($r)) {
1020 logger("Can't detect user data for uid ".$uid, LOGGER_DEBUG);
1024 $page_owner_nick = $r[0]['nickname'];
1027 /// $default_cid = $r[0]['id'];
1028 /// $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
1030 if ((strlen($imagedata) == 0) && ($url == "")) {
1031 logger("No image data and no url provided", LOGGER_DEBUG);
1033 } elseif (strlen($imagedata) == 0) {
1034 logger("Uploading picture from ".$url, LOGGER_DEBUG);
1036 $stamp1 = microtime(true);
1037 $imagedata = @file_get_contents($url);
1038 $a->save_timestamp($stamp1, "file");
1041 $maximagesize = Config::get('system', 'maximagesize');
1043 if (($maximagesize) && (strlen($imagedata) > $maximagesize)) {
1044 logger("Image exceeds size limit of ".$maximagesize, LOGGER_DEBUG);
1048 $tempfile = tempnam(get_temppath(), "cache");
1050 $stamp1 = microtime(true);
1051 file_put_contents($tempfile, $imagedata);
1052 $a->save_timestamp($stamp1, "file");
1054 $data = getimagesize($tempfile);
1056 if (!isset($data["mime"])) {
1058 logger("File is no picture", LOGGER_DEBUG);
1062 $ph = new Photo($imagedata, $data["mime"]);
1064 if (!$ph->isValid()) {
1066 logger("Picture is no valid picture", LOGGER_DEBUG);
1070 $ph->orient($tempfile);
1073 $max_length = Config::get('system', 'max_image_length');
1074 if (! $max_length) {
1075 $max_length = MAX_IMAGE_LENGTH;
1078 if ($max_length > 0) {
1079 $ph->scaleImage($max_length);
1082 $width = $ph->getWidth();
1083 $height = $ph->getHeight();
1085 $hash = photo_new_resource();
1089 // Pictures are always public by now
1090 //$defperm = '<'.$default_cid.'>';
1094 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 0, 0, $defperm);
1097 logger("Picture couldn't be stored", LOGGER_DEBUG);
1101 $image = array("page" => System::baseUrl().'/photos/'.$page_owner_nick.'/image/'.$hash,
1102 "full" => System::baseUrl()."/photo/{$hash}-0.".$ph->getExt());
1104 if ($width > 800 || $height > 800) {
1105 $image["large"] = System::baseUrl()."/photo/{$hash}-0.".$ph->getExt();
1108 if ($width > 640 || $height > 640) {
1109 $ph->scaleImage(640);
1110 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm);
1112 $image["medium"] = System::baseUrl()."/photo/{$hash}-1.".$ph->getExt();
1116 if ($width > 320 || $height > 320) {
1117 $ph->scaleImage(320);
1118 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm);
1120 $image["small"] = System::baseUrl()."/photo/{$hash}-2.".$ph->getExt();
1124 if ($width > 160 && $height > 160) {
1128 $min = $ph->getWidth();
1130 $x = ($min - 160) / 2;
1133 if ($ph->getHeight() < $min) {
1134 $min = $ph->getHeight();
1136 $y = ($min - 160) / 2;
1141 $ph->cropImage(160, $x, $y, $min, $min);
1143 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
1145 $image["thumb"] = System::baseUrl()."/photo/{$hash}-3.".$ph->getExt();
1149 // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
1150 $image["preview"] = $image["full"];
1152 // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
1153 //if (isset($image["thumb"]))
1154 // $image["preview"] = $image["thumb"];
1156 // Unsure, if this should be activated or deactivated
1157 //if (isset($image["small"]))
1158 // $image["preview"] = $image["small"];
1160 if (isset($image["medium"])) {
1161 $image["preview"] = $image["medium"];