3 * @file include/Photo.php
4 * @brief This file contains the Photo class for image processing
8 use Friendica\Core\Config;
9 use Friendica\Core\System;
10 use Friendica\Database\DBM;
12 require_once("include/photos.php");
19 * Put back gd stuff, not everybody have Imagick
29 * @brief supported mimetypes and corresponding file extensions
31 public static function supportedTypes() {
32 if (class_exists('Imagick')) {
34 // Imagick::queryFormats won't help us a lot there...
35 // At least, not yet, other parts of friendica uses this array
37 'image/jpeg' => 'jpg',
43 $t['image/jpeg'] ='jpg';
44 if (imagetypes() & IMG_PNG) {
45 $t['image/png'] = 'png';
52 public function __construct($data, $type=null) {
53 $this->imagick = class_exists('Imagick');
54 $this->types = static::supportedTypes();
55 if (!array_key_exists($type, $this->types)){
60 if ($this->is_imagick() && $this->load_data($data)) {
63 // Failed to load with Imagick, fallback
64 $this->imagick = false;
66 return $this->load_data($data);
69 public function __destruct() {
71 if ($this->is_imagick()) {
72 $this->image->clear();
73 $this->image->destroy();
76 if (is_resource($this->image)) {
77 imagedestroy($this->image);
82 public function is_imagick() {
83 return $this->imagick;
87 * @brief Maps Mime types to Imagick formats
88 * @return arr With with image formats (mime type as key)
90 public function get_FormatsMap() {
92 'image/jpeg' => 'JPG',
99 private function load_data($data) {
100 if ($this->is_imagick()) {
101 $this->image = new Imagick();
103 $this->image->readImageBlob($data);
104 } catch (Exception $e) {
105 // Imagick couldn't use the data
110 * Setup the image to the format it will be saved to
112 $map = $this->get_FormatsMap();
113 $format = $map[$type];
114 $this->image->setFormat($format);
116 // Always coalesce, if it is not a multi-frame image it won't hurt anyway
117 $this->image = $this->image->coalesceImages();
120 * setup the compression here, so we'll do it only once
122 switch($this->getType()){
124 $quality = Config::get('system', 'png_quality');
125 if ((! $quality) || ($quality > 9)) {
126 $quality = PNG_QUALITY;
129 * From http://www.imagemagick.org/script/command-line-options.php#quality:
131 * 'For the MNG and PNG image formats, the quality value sets
132 * the zlib compression level (quality / 10) and filter-type (quality % 10).
133 * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering,
134 * unless the image has a color map, in which case it means compression level 7 with no PNG filtering'
136 $quality = $quality * 10;
137 $this->image->setCompressionQuality($quality);
140 $quality = Config::get('system', 'jpeg_quality');
141 if ((! $quality) || ($quality > 100)) {
142 $quality = JPEG_QUALITY;
144 $this->image->setCompressionQuality($quality);
147 // The 'width' and 'height' properties are only used by non-Imagick routines.
148 $this->width = $this->image->getImageWidth();
149 $this->height = $this->image->getImageHeight();
155 $this->valid = false;
156 $this->image = @imagecreatefromstring($data);
157 if ($this->image !== false) {
158 $this->width = imagesx($this->image);
159 $this->height = imagesy($this->image);
161 imagealphablending($this->image, false);
162 imagesavealpha($this->image, true);
170 public function is_valid() {
171 if ($this->is_imagick()) {
172 return ($this->image !== false);
177 public function getWidth() {
178 if (!$this->is_valid()) {
182 if ($this->is_imagick()) {
183 return $this->image->getImageWidth();
188 public function getHeight() {
189 if (!$this->is_valid()) {
193 if ($this->is_imagick()) {
194 return $this->image->getImageHeight();
196 return $this->height;
199 public function getImage() {
200 if (!$this->is_valid()) {
204 if ($this->is_imagick()) {
206 $this->image = $this->image->deconstructImages();
212 public function getType() {
213 if (!$this->is_valid()) {
220 public function getExt() {
221 if (!$this->is_valid()) {
225 return $this->types[$this->getType()];
228 public function scaleImage($max) {
229 if (!$this->is_valid()) {
233 $width = $this->getWidth();
234 $height = $this->getHeight();
236 $dest_width = $dest_height = 0;
238 if ((! $width)|| (! $height)) {
242 if ($width > $max && $height > $max) {
244 // very tall image (greater than 16:9)
245 // constrain the width - let the height float.
247 if ((($height * 9) / 16) > $width) {
249 $dest_height = intval(($height * $max) / $width);
250 } elseif ($width > $height) {
251 // else constrain both dimensions
253 $dest_height = intval(($height * $max) / $width);
255 $dest_width = intval(($width * $max) / $height);
261 $dest_height = intval(($height * $max) / $width);
263 if ($height > $max) {
265 // very tall image (greater than 16:9)
266 // but width is OK - don't do anything
268 if ((($height * 9) / 16) > $width) {
269 $dest_width = $width;
270 $dest_height = $height;
272 $dest_width = intval(($width * $max) / $height);
276 $dest_width = $width;
277 $dest_height = $height;
283 if ($this->is_imagick()) {
285 * If it is not animated, there will be only one iteration here,
286 * so don't bother checking
288 // Don't forget to go back to the first frame
289 $this->image->setFirstIterator();
292 // FIXME - implement horizantal bias for scaling as in followin GD functions
293 // to allow very tall images to be constrained only horizontally.
295 $this->image->scaleImage($dest_width, $dest_height);
296 } while ($this->image->nextImage());
298 // These may not be necessary any more
299 $this->width = $this->image->getImageWidth();
300 $this->height = $this->image->getImageHeight();
306 $dest = imagecreatetruecolor($dest_width, $dest_height);
307 imagealphablending($dest, false);
308 imagesavealpha($dest, true);
309 if ($this->type=='image/png') {
310 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
312 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
314 imagedestroy($this->image);
316 $this->image = $dest;
317 $this->width = imagesx($this->image);
318 $this->height = imagesy($this->image);
321 public function rotate($degrees) {
322 if (!$this->is_valid()) {
326 if ($this->is_imagick()) {
327 $this->image->setFirstIterator();
329 $this->image->rotateImage(new ImagickPixel(), -$degrees); // ImageMagick rotates in the opposite direction of imagerotate()
330 } while ($this->image->nextImage());
334 // if script dies at this point check memory_limit setting in php.ini
335 $this->image = imagerotate($this->image,$degrees,0);
336 $this->width = imagesx($this->image);
337 $this->height = imagesy($this->image);
340 public function flip($horiz = true, $vert = false) {
341 if (!$this->is_valid()) {
345 if ($this->is_imagick()) {
346 $this->image->setFirstIterator();
349 $this->image->flipImage();
352 $this->image->flopImage();
354 } while ($this->image->nextImage());
358 $w = imagesx($this->image);
359 $h = imagesy($this->image);
360 $flipped = imagecreate($w, $h);
362 for ($x = 0; $x < $w; $x++) {
363 imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h);
367 for ($y = 0; $y < $h; $y++) {
368 imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1);
371 $this->image = $flipped;
374 public function orient($filename) {
375 if ($this->is_imagick()) {
376 // based off comment on http://php.net/manual/en/imagick.getimageorientation.php
377 $orientation = $this->image->getImageOrientation();
378 switch ($orientation) {
379 case imagick::ORIENTATION_BOTTOMRIGHT:
380 $this->image->rotateimage("#000", 180);
382 case imagick::ORIENTATION_RIGHTTOP:
383 $this->image->rotateimage("#000", 90);
385 case imagick::ORIENTATION_LEFTBOTTOM:
386 $this->image->rotateimage("#000", -90);
390 $this->image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
393 // based off comment on http://php.net/manual/en/function.imagerotate.php
395 if (!$this->is_valid()) {
399 if ((!function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) {
403 $exif = @exif_read_data($filename,null,true);
408 $ort = $exif['IFD0']['Orientation'];
415 case 2: // horizontal flip
419 case 3: // 180 rotate left
423 case 4: // vertical flip
424 $this->flip(false, true);
427 case 5: // vertical flip + 90 rotate right
428 $this->flip(false, true);
432 case 6: // 90 rotate right
436 case 7: // horizontal flip + 90 rotate right
441 case 8: // 90 rotate left
446 // logger('exif: ' . print_r($exif,true));
453 public function scaleImageUp($min) {
454 if (!$this->is_valid()) {
459 $width = $this->getWidth();
460 $height = $this->getHeight();
462 $dest_width = $dest_height = 0;
464 if ((!$width)|| (!$height)) {
468 if ($width < $min && $height < $min) {
469 if ($width > $height) {
471 $dest_height = intval(($height * $min) / $width);
473 $dest_width = intval(($width * $min) / $height);
479 $dest_height = intval(($height * $min) / $width);
481 if ($height < $min) {
482 $dest_width = intval(($width * $min) / $height);
485 $dest_width = $width;
486 $dest_height = $height;
491 if ($this->is_imagick()) {
492 return $this->scaleImage($dest_width, $dest_height);
495 $dest = imagecreatetruecolor($dest_width, $dest_height);
496 imagealphablending($dest, false);
497 imagesavealpha($dest, true);
498 if ($this->type=='image/png') {
499 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
501 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
503 imagedestroy($this->image);
505 $this->image = $dest;
506 $this->width = imagesx($this->image);
507 $this->height = imagesy($this->image);
512 public function scaleImageSquare($dim) {
513 if (!$this->is_valid()) {
517 if ($this->is_imagick()) {
518 $this->image->setFirstIterator();
520 $this->image->scaleImage($dim, $dim);
521 } while ($this->image->nextImage());
525 $dest = imagecreatetruecolor($dim, $dim);
526 imagealphablending($dest, false);
527 imagesavealpha($dest, true);
528 if ($this->type=='image/png') {
529 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
531 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height);
533 imagedestroy($this->image);
535 $this->image = $dest;
536 $this->width = imagesx($this->image);
537 $this->height = imagesy($this->image);
541 public function cropImage($max, $x, $y, $w, $h) {
542 if (!$this->is_valid()) {
546 if ($this->is_imagick()) {
547 $this->image->setFirstIterator();
549 $this->image->cropImage($w, $h, $x, $y);
551 * We need to remove the canva,
552 * or the image is not resized to the crop:
553 * http://php.net/manual/en/imagick.cropimage.php#97232
555 $this->image->setImagePage(0, 0, 0, 0);
556 } while ($this->image->nextImage());
557 return $this->scaleImage($max);
560 $dest = imagecreatetruecolor($max, $max);
561 imagealphablending($dest, false);
562 imagesavealpha($dest, true);
563 if ($this->type=='image/png') {
564 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
566 imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
568 imagedestroy($this->image);
570 $this->image = $dest;
571 $this->width = imagesx($this->image);
572 $this->height = imagesy($this->image);
575 public function saveImage($path) {
576 if (!$this->is_valid()) {
580 $string = $this->imageString();
584 $stamp1 = microtime(true);
585 file_put_contents($path, $string);
586 $a->save_timestamp($stamp1, "file");
589 public function imageString() {
590 if (!$this->is_valid()) {
594 if ($this->is_imagick()) {
596 $this->image = $this->image->deconstructImages();
597 $string = $this->image->getImagesBlob();
605 // Enable interlacing
606 imageinterlace($this->image, true);
608 switch($this->getType()){
610 $quality = Config::get('system', 'png_quality');
611 if ((!$quality) || ($quality > 9)) {
612 $quality = PNG_QUALITY;
614 imagepng($this->image, null, $quality);
617 $quality = Config::get('system', 'jpeg_quality');
618 if ((!$quality) || ($quality > 100)) {
619 $quality = JPEG_QUALITY;
621 imagejpeg($this->image, null, $quality);
623 $string = ob_get_contents();
631 public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '') {
633 $r = dba::select('photo', array('guid'), array("`resource-id` = ? AND `guid` != ?", $rid, ''), array('limit' => 1));
634 if (DBM::is_result($r)) {
640 $x = dba::select('photo', array('id'), array('resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale), array('limit' => 1));
642 $fields = array('uid' => $uid, 'contact-id' => $cid, 'guid' => $guid, 'resource-id' => $rid, 'created' => datetime_convert(), 'edited' => datetime_convert(),
643 'filename' => basename($filename), 'type' => $this->getType(), 'album' => $album, 'height' => $this->getHeight(), 'width' => $this->getWidth(),
644 'datasize' => strlen($this->imageString()), 'data' => $this->imageString(), 'scale' => $scale, 'profile' => $profile,
645 'allow_cid' => $allow_cid, 'allow_gid' => $allow_gid, 'deny_cid' => $deny_cid, 'deny_gid' => $deny_gid, 'desc' => $desc);
647 if (DBM::is_result($x)) {
648 $r = dba::update('photo', $fields, array('id' => $x['id']));
650 $r = dba::insert('photo', $fields);
659 * Guess image mimetype from filename or from Content-Type header
661 * @arg $filename string Image filename
662 * @arg $fromcurl boolean Check Content-Type header from curl request
664 function guess_image_type($filename, $fromcurl=false) {
665 logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
670 $h = explode("\n",$a->get_curl_headers());
672 list($k,$v) = array_map("trim", explode(":", trim($l), 2));
675 if (array_key_exists('Content-Type', $headers))
676 $type = $headers['Content-Type'];
679 // Guessing from extension? Isn't that... dangerous?
680 if (class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
682 * Well, this not much better,
683 * but at least it comes from the data inside the image,
684 * we won't be tricked by a manipulated extension
686 $image = new Imagick($filename);
687 $type = $image->getImageMimeType();
688 $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
690 $ext = pathinfo($filename, PATHINFO_EXTENSION);
691 $types = Photo::supportedTypes();
692 $type = "image/jpeg";
693 foreach ($types as $m => $e){
700 logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG);
706 * @brief Updates the avatar links in a contact only if needed
708 * @param string $avatar Link to avatar picture
709 * @param int $uid User id of contact owner
710 * @param int $cid Contact id
711 * @param bool $force force picture update
713 * @return array Returns array of the different avatar sizes
715 function update_contact_avatar($avatar, $uid, $cid, $force = false) {
716 $r = q("SELECT `avatar`, `photo`, `thumb`, `micro`, `nurl` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
717 if (!DBM::is_result($r)) {
720 $data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
723 if (($r[0]["avatar"] != $avatar) || $force) {
724 $photos = import_profile_photo($avatar, $uid, $cid, true);
727 q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
728 dbesc($avatar), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
729 dbesc(datetime_convert()), intval($cid));
731 // Update the public contact (contact id = 0)
733 $pcontact = dba::select('contact', array('id'), array('nurl' => $r[0]['nurl']), array('limit' => 1));
734 if (DBM::is_result($pcontact)) {
735 update_contact_avatar($avatar, 0, $pcontact['id'], $force);
746 function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) {
748 $r = q("SELECT `resource-id` FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `scale` = 4 AND `album` = 'Contact Photos' LIMIT 1",
752 if (DBM::is_result($r) && strlen($r[0]['resource-id'])) {
753 $hash = $r[0]['resource-id'];
755 $hash = photo_new_resource();
758 $photo_failure = false;
760 $filename = basename($photo);
761 $img_str = fetch_url($photo, true);
763 if ($quit_on_error && ($img_str == "")) {
767 $type = guess_image_type($photo, true);
768 $img = new Photo($img_str, $type);
769 if ($img->is_valid()) {
771 $img->scaleImageSquare(175);
773 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4);
776 $photo_failure = true;
778 $img->scaleImage(80);
780 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5);
783 $photo_failure = true;
785 $img->scaleImage(48);
787 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6);
790 $photo_failure = true;
793 $suffix = '?ts='.time();
795 $photo = System::baseUrl() . '/photo/' . $hash . '-4.' . $img->getExt() . $suffix;
796 $thumb = System::baseUrl() . '/photo/' . $hash . '-5.' . $img->getExt() . $suffix;
797 $micro = System::baseUrl() . '/photo/' . $hash . '-6.' . $img->getExt() . $suffix;
799 // Remove the cached photo
801 $basepath = $a->get_basepath();
803 if (is_dir($basepath."/photo")) {
804 $filename = $basepath.'/photo/'.$hash.'-4.'.$img->getExt();
805 if (file_exists($filename)) {
808 $filename = $basepath.'/photo/'.$hash.'-5.'.$img->getExt();
809 if (file_exists($filename)) {
812 $filename = $basepath.'/photo/'.$hash.'-6.'.$img->getExt();
813 if (file_exists($filename)) {
818 $photo_failure = true;
821 if ($photo_failure && $quit_on_error) {
825 if ($photo_failure) {
826 $photo = System::baseUrl() . '/images/person-175.jpg';
827 $thumb = System::baseUrl() . '/images/person-80.jpg';
828 $micro = System::baseUrl() . '/images/person-48.jpg';
831 return(array($photo,$thumb,$micro));
835 function get_photo_info($url) {
838 $data = Cache::get($url);
840 if (is_null($data) || !$data || !is_array($data)) {
841 $img_str = fetch_url($url, true, $redirects, 4);
842 $filesize = strlen($img_str);
844 if (function_exists("getimagesizefromstring")) {
845 $data = getimagesizefromstring($img_str);
847 $tempfile = tempnam(get_temppath(), "cache");
850 $stamp1 = microtime(true);
851 file_put_contents($tempfile, $img_str);
852 $a->save_timestamp($stamp1, "file");
854 $data = getimagesize($tempfile);
859 $data["size"] = $filesize;
862 Cache::set($url, $data);
868 function scale_image($width, $height, $max) {
870 $dest_width = $dest_height = 0;
872 if ((!$width) || (!$height)) {
876 if ($width > $max && $height > $max) {
878 // very tall image (greater than 16:9)
879 // constrain the width - let the height float.
881 if ((($height * 9) / 16) > $width) {
883 $dest_height = intval(($height * $max) / $width);
884 } elseif ($width > $height) {
885 // else constrain both dimensions
887 $dest_height = intval(($height * $max) / $width);
889 $dest_width = intval(($width * $max) / $height);
895 $dest_height = intval(($height * $max) / $width);
897 if ($height > $max) {
899 // very tall image (greater than 16:9)
900 // but width is OK - don't do anything
902 if ((($height * 9) / 16) > $width) {
903 $dest_width = $width;
904 $dest_height = $height;
906 $dest_width = intval(($width * $max) / $height);
910 $dest_width = $width;
911 $dest_height = $height;
915 return array("width" => $dest_width, "height" => $dest_height);
918 function store_photo(App $a, $uid, $imagedata = "", $url = "") {
919 $r = q("SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
920 WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1",
923 if (!DBM::is_result($r)) {
924 logger("Can't detect user data for uid ".$uid, LOGGER_DEBUG);
928 $page_owner_nick = $r[0]['nickname'];
931 /// $default_cid = $r[0]['id'];
932 /// $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
934 if ((strlen($imagedata) == 0) && ($url == "")) {
935 logger("No image data and no url provided", LOGGER_DEBUG);
937 } elseif (strlen($imagedata) == 0) {
938 logger("Uploading picture from ".$url, LOGGER_DEBUG);
940 $stamp1 = microtime(true);
941 $imagedata = @file_get_contents($url);
942 $a->save_timestamp($stamp1, "file");
945 $maximagesize = Config::get('system', 'maximagesize');
947 if (($maximagesize) && (strlen($imagedata) > $maximagesize)) {
948 logger("Image exceeds size limit of ".$maximagesize, LOGGER_DEBUG);
952 $tempfile = tempnam(get_temppath(), "cache");
954 $stamp1 = microtime(true);
955 file_put_contents($tempfile, $imagedata);
956 $a->save_timestamp($stamp1, "file");
958 $data = getimagesize($tempfile);
960 if (!isset($data["mime"])) {
962 logger("File is no picture", LOGGER_DEBUG);
966 $ph = new Photo($imagedata, $data["mime"]);
968 if (!$ph->is_valid()) {
970 logger("Picture is no valid picture", LOGGER_DEBUG);
974 $ph->orient($tempfile);
977 $max_length = Config::get('system', 'max_image_length');
979 $max_length = MAX_IMAGE_LENGTH;
981 if ($max_length > 0) {
982 $ph->scaleImage($max_length);
985 $width = $ph->getWidth();
986 $height = $ph->getHeight();
988 $hash = photo_new_resource();
992 // Pictures are always public by now
993 //$defperm = '<'.$default_cid.'>';
997 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 0, 0, $defperm);
1000 logger("Picture couldn't be stored", LOGGER_DEBUG);
1004 $image = array("page" => System::baseUrl().'/photos/'.$page_owner_nick.'/image/'.$hash,
1005 "full" => System::baseUrl()."/photo/{$hash}-0.".$ph->getExt());
1007 if ($width > 800 || $height > 800) {
1008 $image["large"] = System::baseUrl()."/photo/{$hash}-0.".$ph->getExt();
1011 if ($width > 640 || $height > 640) {
1012 $ph->scaleImage(640);
1013 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm);
1015 $image["medium"] = System::baseUrl()."/photo/{$hash}-1.".$ph->getExt();
1019 if ($width > 320 || $height > 320) {
1020 $ph->scaleImage(320);
1021 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm);
1023 $image["small"] = System::baseUrl()."/photo/{$hash}-2.".$ph->getExt();
1027 if ($width > 160 && $height > 160) {
1031 $min = $ph->getWidth();
1033 $x = ($min - 160) / 2;
1036 if ($ph->getHeight() < $min) {
1037 $min = $ph->getHeight();
1039 $y = ($min - 160) / 2;
1044 $ph->cropImage(160, $x, $y, $min, $min);
1046 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
1048 $image["thumb"] = System::baseUrl()."/photo/{$hash}-3.".$ph->getExt();
1052 // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
1053 $image["preview"] = $image["full"];
1055 // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
1056 //if (isset($image["thumb"]))
1057 // $image["preview"] = $image["thumb"];
1059 // Unsure, if this should be activated or deactivated
1060 //if (isset($image["small"]))
1061 // $image["preview"] = $image["small"];
1063 if (isset($image["medium"])) {
1064 $image["preview"] = $image["medium"];