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;
14 require_once "include/photos.php";
21 * Put back gd stuff, not everybody have Imagick
31 * @brief supported mimetypes and corresponding file extensions
33 public static function supportedTypes() {
34 if (class_exists('Imagick')) {
36 // Imagick::queryFormats won't help us a lot there...
37 // At least, not yet, other parts of friendica uses this array
39 'image/jpeg' => 'jpg',
45 $t['image/jpeg'] ='jpg';
46 if (imagetypes() & IMG_PNG) {
47 $t['image/png'] = 'png';
54 public function __construct($data, $type=null)
56 $this->imagick = class_exists('Imagick');
57 $this->types = static::supportedTypes();
58 if (!array_key_exists($type, $this->types)){
63 if ($this->is_imagick() && $this->load_data($data)) {
66 // Failed to load with Imagick, fallback
67 $this->imagick = false;
69 return $this->load_data($data);
72 public function __destruct() {
74 if ($this->is_imagick()) {
75 $this->image->clear();
76 $this->image->destroy();
79 if (is_resource($this->image)) {
80 imagedestroy($this->image);
85 public function is_imagick()
87 return $this->imagick;
91 * @brief Maps Mime types to Imagick formats
92 * @return arr With with image formats (mime type as key)
94 public function get_FormatsMap() {
96 'image/jpeg' => 'JPG',
103 private function load_data($data) {
104 if ($this->is_imagick()) {
105 $this->image = new Imagick();
107 $this->image->readImageBlob($data);
108 } catch (Exception $e) {
109 // Imagick couldn't use the data
114 * Setup the image to the format it will be saved to
116 $map = $this->get_FormatsMap();
117 $format = $map[$type];
118 $this->image->setFormat($format);
120 // Always coalesce, if it is not a multi-frame image it won't hurt anyway
121 $this->image = $this->image->coalesceImages();
124 * setup the compression here, so we'll do it only once
126 switch($this->getType()){
128 $quality = Config::get('system', 'png_quality');
129 if ((! $quality) || ($quality > 9)) {
130 $quality = PNG_QUALITY;
133 * From http://www.imagemagick.org/script/command-line-options.php#quality:
135 * 'For the MNG and PNG image formats, the quality value sets
136 * the zlib compression level (quality / 10) and filter-type (quality % 10).
137 * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering,
138 * unless the image has a color map, in which case it means compression level 7 with no PNG filtering'
140 $quality = $quality * 10;
141 $this->image->setCompressionQuality($quality);
144 $quality = Config::get('system', 'jpeg_quality');
145 if ((! $quality) || ($quality > 100)) {
146 $quality = JPEG_QUALITY;
148 $this->image->setCompressionQuality($quality);
151 // The 'width' and 'height' properties are only used by non-Imagick routines.
152 $this->width = $this->image->getImageWidth();
153 $this->height = $this->image->getImageHeight();
159 $this->valid = false;
160 $this->image = @imagecreatefromstring($data);
161 if ($this->image !== false) {
162 $this->width = imagesx($this->image);
163 $this->height = imagesy($this->image);
165 imagealphablending($this->image, false);
166 imagesavealpha($this->image, true);
174 public function is_valid() {
175 if ($this->is_imagick()) {
176 return ($this->image !== false);
181 public function getWidth() {
182 if (!$this->is_valid()) {
186 if ($this->is_imagick()) {
187 return $this->image->getImageWidth();
192 public function getHeight() {
193 if (!$this->is_valid()) {
197 if ($this->is_imagick()) {
198 return $this->image->getImageHeight();
200 return $this->height;
203 public function getImage() {
204 if (!$this->is_valid()) {
208 if ($this->is_imagick()) {
210 $this->image = $this->image->deconstructImages();
216 public function getType() {
217 if (!$this->is_valid()) {
224 public function getExt() {
225 if (!$this->is_valid()) {
229 return $this->types[$this->getType()];
232 public function scaleImage($max) {
233 if (!$this->is_valid()) {
237 $width = $this->getWidth();
238 $height = $this->getHeight();
240 $dest_width = $dest_height = 0;
242 if ((! $width)|| (! $height)) {
246 if ($width > $max && $height > $max) {
248 // very tall image (greater than 16:9)
249 // constrain the width - let the height float.
251 if ((($height * 9) / 16) > $width) {
253 $dest_height = intval(($height * $max) / $width);
254 } elseif ($width > $height) {
255 // else constrain both dimensions
257 $dest_height = intval(($height * $max) / $width);
259 $dest_width = intval(($width * $max) / $height);
265 $dest_height = intval(($height * $max) / $width);
267 if ($height > $max) {
269 // very tall image (greater than 16:9)
270 // but width is OK - don't do anything
272 if ((($height * 9) / 16) > $width) {
273 $dest_width = $width;
274 $dest_height = $height;
276 $dest_width = intval(($width * $max) / $height);
280 $dest_width = $width;
281 $dest_height = $height;
287 if ($this->is_imagick()) {
289 * If it is not animated, there will be only one iteration here,
290 * so don't bother checking
292 // Don't forget to go back to the first frame
293 $this->image->setFirstIterator();
296 // FIXME - implement horizantal bias for scaling as in followin GD functions
297 // to allow very tall images to be constrained only horizontally.
299 $this->image->scaleImage($dest_width, $dest_height);
300 } while ($this->image->nextImage());
302 // These may not be necessary any more
303 $this->width = $this->image->getImageWidth();
304 $this->height = $this->image->getImageHeight();
310 $dest = imagecreatetruecolor($dest_width, $dest_height);
311 imagealphablending($dest, false);
312 imagesavealpha($dest, true);
313 if ($this->type=='image/png') {
314 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
316 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
318 imagedestroy($this->image);
320 $this->image = $dest;
321 $this->width = imagesx($this->image);
322 $this->height = imagesy($this->image);
325 public function rotate($degrees) {
326 if (!$this->is_valid()) {
330 if ($this->is_imagick()) {
331 $this->image->setFirstIterator();
333 $this->image->rotateImage(new ImagickPixel(), -$degrees); // ImageMagick rotates in the opposite direction of imagerotate()
334 } while ($this->image->nextImage());
338 // if script dies at this point check memory_limit setting in php.ini
339 $this->image = imagerotate($this->image,$degrees,0);
340 $this->width = imagesx($this->image);
341 $this->height = imagesy($this->image);
344 public function flip($horiz = true, $vert = false) {
345 if (!$this->is_valid()) {
349 if ($this->is_imagick()) {
350 $this->image->setFirstIterator();
353 $this->image->flipImage();
356 $this->image->flopImage();
358 } while ($this->image->nextImage());
362 $w = imagesx($this->image);
363 $h = imagesy($this->image);
364 $flipped = imagecreate($w, $h);
366 for ($x = 0; $x < $w; $x++) {
367 imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h);
371 for ($y = 0; $y < $h; $y++) {
372 imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1);
375 $this->image = $flipped;
378 public function orient($filename) {
379 if ($this->is_imagick()) {
380 // based off comment on http://php.net/manual/en/imagick.getimageorientation.php
381 $orientation = $this->image->getImageOrientation();
382 switch ($orientation) {
383 case imagick::ORIENTATION_BOTTOMRIGHT:
384 $this->image->rotateimage("#000", 180);
386 case imagick::ORIENTATION_RIGHTTOP:
387 $this->image->rotateimage("#000", 90);
389 case imagick::ORIENTATION_LEFTBOTTOM:
390 $this->image->rotateimage("#000", -90);
394 $this->image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
397 // based off comment on http://php.net/manual/en/function.imagerotate.php
399 if (!$this->is_valid()) {
403 if ((!function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) {
407 $exif = @exif_read_data($filename,null,true);
412 $ort = $exif['IFD0']['Orientation'];
419 case 2: // horizontal flip
423 case 3: // 180 rotate left
427 case 4: // vertical flip
428 $this->flip(false, true);
431 case 5: // vertical flip + 90 rotate right
432 $this->flip(false, true);
436 case 6: // 90 rotate right
440 case 7: // horizontal flip + 90 rotate right
445 case 8: // 90 rotate left
450 // logger('exif: ' . print_r($exif,true));
457 public function scaleImageUp($min) {
458 if (!$this->is_valid()) {
463 $width = $this->getWidth();
464 $height = $this->getHeight();
466 $dest_width = $dest_height = 0;
468 if ((!$width)|| (!$height)) {
472 if ($width < $min && $height < $min) {
473 if ($width > $height) {
475 $dest_height = intval(($height * $min) / $width);
477 $dest_width = intval(($width * $min) / $height);
483 $dest_height = intval(($height * $min) / $width);
485 if ($height < $min) {
486 $dest_width = intval(($width * $min) / $height);
489 $dest_width = $width;
490 $dest_height = $height;
495 if ($this->is_imagick()) {
496 return $this->scaleImage($dest_width, $dest_height);
499 $dest = imagecreatetruecolor($dest_width, $dest_height);
500 imagealphablending($dest, false);
501 imagesavealpha($dest, true);
502 if ($this->type=='image/png') {
503 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
505 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
507 imagedestroy($this->image);
509 $this->image = $dest;
510 $this->width = imagesx($this->image);
511 $this->height = imagesy($this->image);
516 public function scaleImageSquare($dim) {
517 if (!$this->is_valid()) {
521 if ($this->is_imagick()) {
522 $this->image->setFirstIterator();
524 $this->image->scaleImage($dim, $dim);
525 } while ($this->image->nextImage());
529 $dest = imagecreatetruecolor($dim, $dim);
530 imagealphablending($dest, false);
531 imagesavealpha($dest, true);
532 if ($this->type=='image/png') {
533 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
535 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height);
537 imagedestroy($this->image);
539 $this->image = $dest;
540 $this->width = imagesx($this->image);
541 $this->height = imagesy($this->image);
545 public function cropImage($max, $x, $y, $w, $h) {
546 if (!$this->is_valid()) {
550 if ($this->is_imagick()) {
551 $this->image->setFirstIterator();
553 $this->image->cropImage($w, $h, $x, $y);
555 * We need to remove the canva,
556 * or the image is not resized to the crop:
557 * http://php.net/manual/en/imagick.cropimage.php#97232
559 $this->image->setImagePage(0, 0, 0, 0);
560 } while ($this->image->nextImage());
561 return $this->scaleImage($max);
564 $dest = imagecreatetruecolor($max, $max);
565 imagealphablending($dest, false);
566 imagesavealpha($dest, true);
567 if ($this->type=='image/png') {
568 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
570 imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
572 imagedestroy($this->image);
574 $this->image = $dest;
575 $this->width = imagesx($this->image);
576 $this->height = imagesy($this->image);
579 public function saveImage($path) {
580 if (!$this->is_valid()) {
584 $string = $this->imageString();
588 $stamp1 = microtime(true);
589 file_put_contents($path, $string);
590 $a->save_timestamp($stamp1, "file");
593 public function imageString() {
594 if (!$this->is_valid()) {
598 if ($this->is_imagick()) {
600 $this->image = $this->image->deconstructImages();
601 $string = $this->image->getImagesBlob();
609 // Enable interlacing
610 imageinterlace($this->image, true);
612 switch($this->getType()){
614 $quality = Config::get('system', 'png_quality');
615 if ((!$quality) || ($quality > 9)) {
616 $quality = PNG_QUALITY;
618 imagepng($this->image, null, $quality);
621 $quality = Config::get('system', 'jpeg_quality');
622 if ((!$quality) || ($quality > 100)) {
623 $quality = JPEG_QUALITY;
625 imagejpeg($this->image, null, $quality);
627 $string = ob_get_contents();
635 public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '') {
637 $r = dba::select('photo', array('guid'), array("`resource-id` = ? AND `guid` != ?", $rid, ''), array('limit' => 1));
638 if (DBM::is_result($r)) {
644 $x = dba::select('photo', array('id'), array('resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale), array('limit' => 1));
646 $fields = array('uid' => $uid, 'contact-id' => $cid, 'guid' => $guid, 'resource-id' => $rid, 'created' => datetime_convert(), 'edited' => datetime_convert(),
647 'filename' => basename($filename), 'type' => $this->getType(), 'album' => $album, 'height' => $this->getHeight(), 'width' => $this->getWidth(),
648 'datasize' => strlen($this->imageString()), 'data' => $this->imageString(), 'scale' => $scale, 'profile' => $profile,
649 'allow_cid' => $allow_cid, 'allow_gid' => $allow_gid, 'deny_cid' => $deny_cid, 'deny_gid' => $deny_gid, 'desc' => $desc);
651 if (DBM::is_result($x)) {
652 $r = dba::update('photo', $fields, array('id' => $x['id']));
654 $r = dba::insert('photo', $fields);
663 * Guess image mimetype from filename or from Content-Type header
665 * @arg $filename string Image filename
666 * @arg $fromcurl boolean Check Content-Type header from curl request
668 function guess_image_type($filename, $fromcurl=false) {
669 logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
674 $h = explode("\n",$a->get_curl_headers());
676 list($k,$v) = array_map("trim", explode(":", trim($l), 2));
679 if (array_key_exists('Content-Type', $headers))
680 $type = $headers['Content-Type'];
683 // Guessing from extension? Isn't that... dangerous?
684 if (class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
686 * Well, this not much better,
687 * but at least it comes from the data inside the image,
688 * we won't be tricked by a manipulated extension
690 $image = new Imagick($filename);
691 $type = $image->getImageMimeType();
692 $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
694 $ext = pathinfo($filename, PATHINFO_EXTENSION);
695 $types = Photo::supportedTypes();
696 $type = "image/jpeg";
697 foreach ($types as $m => $e){
704 logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG);
710 * @brief Updates the avatar links in a contact only if needed
712 * @param string $avatar Link to avatar picture
713 * @param int $uid User id of contact owner
714 * @param int $cid Contact id
715 * @param bool $force force picture update
717 * @return array Returns array of the different avatar sizes
719 function update_contact_avatar($avatar, $uid, $cid, $force = false) {
720 $r = q("SELECT `avatar`, `photo`, `thumb`, `micro`, `nurl` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
721 if (!DBM::is_result($r)) {
724 $data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
727 if (($r[0]["avatar"] != $avatar) || $force) {
728 $photos = import_profile_photo($avatar, $uid, $cid, true);
731 q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
732 dbesc($avatar), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
733 dbesc(datetime_convert()), intval($cid));
735 // Update the public contact (contact id = 0)
737 $pcontact = dba::select('contact', array('id'), array('nurl' => $r[0]['nurl']), array('limit' => 1));
738 if (DBM::is_result($pcontact)) {
739 update_contact_avatar($avatar, 0, $pcontact['id'], $force);
750 function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) {
752 $r = q("SELECT `resource-id` FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `scale` = 4 AND `album` = 'Contact Photos' LIMIT 1",
756 if (DBM::is_result($r) && strlen($r[0]['resource-id'])) {
757 $hash = $r[0]['resource-id'];
759 $hash = photo_new_resource();
762 $photo_failure = false;
764 $filename = basename($photo);
765 $img_str = fetch_url($photo, true);
767 if ($quit_on_error && ($img_str == "")) {
771 $type = guess_image_type($photo, true);
772 $img = new Photo($img_str, $type);
773 if ($img->is_valid()) {
775 $img->scaleImageSquare(175);
777 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4);
780 $photo_failure = true;
782 $img->scaleImage(80);
784 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5);
787 $photo_failure = true;
789 $img->scaleImage(48);
791 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6);
794 $photo_failure = true;
797 $suffix = '?ts='.time();
799 $photo = System::baseUrl() . '/photo/' . $hash . '-4.' . $img->getExt() . $suffix;
800 $thumb = System::baseUrl() . '/photo/' . $hash . '-5.' . $img->getExt() . $suffix;
801 $micro = System::baseUrl() . '/photo/' . $hash . '-6.' . $img->getExt() . $suffix;
803 // Remove the cached photo
805 $basepath = $a->get_basepath();
807 if (is_dir($basepath."/photo")) {
808 $filename = $basepath.'/photo/'.$hash.'-4.'.$img->getExt();
809 if (file_exists($filename)) {
812 $filename = $basepath.'/photo/'.$hash.'-5.'.$img->getExt();
813 if (file_exists($filename)) {
816 $filename = $basepath.'/photo/'.$hash.'-6.'.$img->getExt();
817 if (file_exists($filename)) {
822 $photo_failure = true;
825 if ($photo_failure && $quit_on_error) {
829 if ($photo_failure) {
830 $photo = System::baseUrl() . '/images/person-175.jpg';
831 $thumb = System::baseUrl() . '/images/person-80.jpg';
832 $micro = System::baseUrl() . '/images/person-48.jpg';
835 return(array($photo,$thumb,$micro));
839 function get_photo_info($url) {
842 $data = Cache::get($url);
844 if (is_null($data) || !$data || !is_array($data)) {
845 $img_str = fetch_url($url, true, $redirects, 4);
846 $filesize = strlen($img_str);
848 if (function_exists("getimagesizefromstring")) {
849 $data = getimagesizefromstring($img_str);
851 $tempfile = tempnam(get_temppath(), "cache");
854 $stamp1 = microtime(true);
855 file_put_contents($tempfile, $img_str);
856 $a->save_timestamp($stamp1, "file");
858 $data = getimagesize($tempfile);
863 $data["size"] = $filesize;
866 Cache::set($url, $data);
872 function scale_image($width, $height, $max) {
874 $dest_width = $dest_height = 0;
876 if ((!$width) || (!$height)) {
880 if ($width > $max && $height > $max) {
882 // very tall image (greater than 16:9)
883 // constrain the width - let the height float.
885 if ((($height * 9) / 16) > $width) {
887 $dest_height = intval(($height * $max) / $width);
888 } elseif ($width > $height) {
889 // else constrain both dimensions
891 $dest_height = intval(($height * $max) / $width);
893 $dest_width = intval(($width * $max) / $height);
899 $dest_height = intval(($height * $max) / $width);
901 if ($height > $max) {
903 // very tall image (greater than 16:9)
904 // but width is OK - don't do anything
906 if ((($height * 9) / 16) > $width) {
907 $dest_width = $width;
908 $dest_height = $height;
910 $dest_width = intval(($width * $max) / $height);
914 $dest_width = $width;
915 $dest_height = $height;
919 return array("width" => $dest_width, "height" => $dest_height);
922 function store_photo(App $a, $uid, $imagedata = "", $url = "") {
923 $r = q("SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
924 WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1",
927 if (!DBM::is_result($r)) {
928 logger("Can't detect user data for uid ".$uid, LOGGER_DEBUG);
932 $page_owner_nick = $r[0]['nickname'];
935 /// $default_cid = $r[0]['id'];
936 /// $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
938 if ((strlen($imagedata) == 0) && ($url == "")) {
939 logger("No image data and no url provided", LOGGER_DEBUG);
941 } elseif (strlen($imagedata) == 0) {
942 logger("Uploading picture from ".$url, LOGGER_DEBUG);
944 $stamp1 = microtime(true);
945 $imagedata = @file_get_contents($url);
946 $a->save_timestamp($stamp1, "file");
949 $maximagesize = Config::get('system', 'maximagesize');
951 if (($maximagesize) && (strlen($imagedata) > $maximagesize)) {
952 logger("Image exceeds size limit of ".$maximagesize, LOGGER_DEBUG);
956 $tempfile = tempnam(get_temppath(), "cache");
958 $stamp1 = microtime(true);
959 file_put_contents($tempfile, $imagedata);
960 $a->save_timestamp($stamp1, "file");
962 $data = getimagesize($tempfile);
964 if (!isset($data["mime"])) {
966 logger("File is no picture", LOGGER_DEBUG);
970 $ph = new Photo($imagedata, $data["mime"]);
972 if (!$ph->is_valid()) {
974 logger("Picture is no valid picture", LOGGER_DEBUG);
978 $ph->orient($tempfile);
981 $max_length = Config::get('system', 'max_image_length');
983 $max_length = MAX_IMAGE_LENGTH;
985 if ($max_length > 0) {
986 $ph->scaleImage($max_length);
989 $width = $ph->getWidth();
990 $height = $ph->getHeight();
992 $hash = photo_new_resource();
996 // Pictures are always public by now
997 //$defperm = '<'.$default_cid.'>';
1001 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 0, 0, $defperm);
1004 logger("Picture couldn't be stored", LOGGER_DEBUG);
1008 $image = array("page" => System::baseUrl().'/photos/'.$page_owner_nick.'/image/'.$hash,
1009 "full" => System::baseUrl()."/photo/{$hash}-0.".$ph->getExt());
1011 if ($width > 800 || $height > 800) {
1012 $image["large"] = System::baseUrl()."/photo/{$hash}-0.".$ph->getExt();
1015 if ($width > 640 || $height > 640) {
1016 $ph->scaleImage(640);
1017 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm);
1019 $image["medium"] = System::baseUrl()."/photo/{$hash}-1.".$ph->getExt();
1023 if ($width > 320 || $height > 320) {
1024 $ph->scaleImage(320);
1025 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm);
1027 $image["small"] = System::baseUrl()."/photo/{$hash}-2.".$ph->getExt();
1031 if ($width > 160 && $height > 160) {
1035 $min = $ph->getWidth();
1037 $x = ($min - 160) / 2;
1040 if ($ph->getHeight() < $min) {
1041 $min = $ph->getHeight();
1043 $y = ($min - 160) / 2;
1048 $ph->cropImage(160, $x, $y, $min, $min);
1050 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
1052 $image["thumb"] = System::baseUrl()."/photo/{$hash}-3.".$ph->getExt();
1056 // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
1057 $image["preview"] = $image["full"];
1059 // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
1060 //if (isset($image["thumb"]))
1061 // $image["preview"] = $image["thumb"];
1063 // Unsure, if this should be activated or deactivated
1064 //if (isset($image["small"]))
1065 // $image["preview"] = $image["small"];
1067 if (isset($image["medium"])) {
1068 $image["preview"] = $image["medium"];