3 * @file include/Photo.php
4 * @brief This file contains the Photo class for image processing
7 require_once("include/photos.php");
14 * Put back gd stuff, not everybody have Imagick
24 * @brief supported mimetypes and corresponding file extensions
26 static function supportedTypes() {
27 if (class_exists('Imagick')) {
29 // Imagick::queryFormats won't help us a lot there...
30 // At least, not yet, other parts of friendica uses this array
32 'image/jpeg' => 'jpg',
38 $t['image/jpeg'] ='jpg';
39 if (imagetypes() & IMG_PNG) {
40 $t['image/png'] = 'png';
47 public function __construct($data, $type=null) {
48 $this->imagick = class_exists('Imagick');
49 $this->types = $this->supportedTypes();
50 if (!array_key_exists($type,$this->types)){
55 if ($this->is_imagick() && $this->load_data($data)) {
58 // Failed to load with Imagick, fallback
59 $this->imagick = false;
61 return $this->load_data($data);
64 public function __destruct() {
66 if ($this->is_imagick()) {
67 $this->image->clear();
68 $this->image->destroy();
71 imagedestroy($this->image);
75 public function is_imagick() {
76 return $this->imagick;
80 * @brief Maps Mime types to Imagick formats
82 public function get_FormatsMap() {
84 'image/jpeg' => 'JPG',
91 private function load_data($data) {
92 if ($this->is_imagick()) {
93 $this->image = new Imagick();
95 $this->image->readImageBlob($data);
97 catch (Exception $e) {
98 // Imagick couldn't use the data
103 * Setup the image to the format it will be saved to
105 $map = $this->get_FormatsMap();
106 $format = $map[$type];
107 $this->image->setFormat($format);
109 // Always coalesce, if it is not a multi-frame image it won't hurt anyway
110 $this->image = $this->image->coalesceImages();
113 * setup the compression here, so we'll do it only once
115 switch($this->getType()){
117 $quality = get_config('system','png_quality');
118 if ((! $quality) || ($quality > 9)) {
119 $quality = PNG_QUALITY;
122 * From http://www.imagemagick.org/script/command-line-options.php#quality:
124 * 'For the MNG and PNG image formats, the quality value sets
125 * the zlib compression level (quality / 10) and filter-type (quality % 10).
126 * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering,
127 * unless the image has a color map, in which case it means compression level 7 with no PNG filtering'
129 $quality = $quality * 10;
130 $this->image->setCompressionQuality($quality);
133 $quality = get_config('system','jpeg_quality');
134 if ((! $quality) || ($quality > 100)) {
135 $quality = JPEG_QUALITY;
137 $this->image->setCompressionQuality($quality);
140 // The 'width' and 'height' properties are only used by non-Imagick routines.
141 $this->width = $this->image->getImageWidth();
142 $this->height = $this->image->getImageHeight();
148 $this->valid = false;
149 $this->image = @imagecreatefromstring($data);
150 if ($this->image !== false) {
151 $this->width = imagesx($this->image);
152 $this->height = imagesy($this->image);
154 imagealphablending($this->image, false);
155 imagesavealpha($this->image, true);
163 public function is_valid() {
164 if ($this->is_imagick()) {
165 return ($this->image !== false);
170 public function getWidth() {
171 if (!$this->is_valid()) {
175 if ($this->is_imagick()) {
176 return $this->image->getImageWidth();
181 public function getHeight() {
182 if (!$this->is_valid()) {
186 if ($this->is_imagick()) {
187 return $this->image->getImageHeight();
189 return $this->height;
192 public function getImage() {
193 if (!$this->is_valid()) {
197 if ($this->is_imagick()) {
199 $this->image = $this->image->deconstructImages();
205 public function getType() {
206 if (!$this->is_valid()) {
213 public function getExt() {
214 if (!$this->is_valid()) {
218 return $this->types[$this->getType()];
221 public function scaleImage($max) {
222 if (!$this->is_valid()) {
226 $width = $this->getWidth();
227 $height = $this->getHeight();
229 $dest_width = $dest_height = 0;
231 if ((! $width)|| (! $height)) {
235 if ($width > $max && $height > $max) {
237 // very tall image (greater than 16:9)
238 // constrain the width - let the height float.
240 if ((($height * 9) / 16) > $width) {
242 $dest_height = intval(( $height * $max ) / $width);
243 } elseif ($width > $height) {
244 // else constrain both dimensions
246 $dest_height = intval(( $height * $max ) / $width);
248 $dest_width = intval(( $width * $max ) / $height);
252 if ( $width > $max ) {
254 $dest_height = intval(( $height * $max ) / $width);
256 if ( $height > $max ) {
258 // very tall image (greater than 16:9)
259 // but width is OK - don't do anything
261 if ((($height * 9) / 16) > $width) {
262 $dest_width = $width;
263 $dest_height = $height;
265 $dest_width = intval(( $width * $max ) / $height);
269 $dest_width = $width;
270 $dest_height = $height;
276 if ($this->is_imagick()) {
278 * If it is not animated, there will be only one iteration here,
279 * so don't bother checking
281 // Don't forget to go back to the first frame
282 $this->image->setFirstIterator();
285 // FIXME - implement horizantal bias for scaling as in followin GD functions
286 // to allow very tall images to be constrained only horizontally.
288 $this->image->scaleImage($dest_width, $dest_height);
289 } while ($this->image->nextImage());
291 // These may not be necessary any more
292 $this->width = $this->image->getImageWidth();
293 $this->height = $this->image->getImageHeight();
299 $dest = imagecreatetruecolor( $dest_width, $dest_height );
300 imagealphablending($dest, false);
301 imagesavealpha($dest, true);
302 if ($this->type=='image/png') {
303 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
305 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
307 imagedestroy($this->image);
309 $this->image = $dest;
310 $this->width = imagesx($this->image);
311 $this->height = imagesy($this->image);
314 public function rotate($degrees) {
315 if (!$this->is_valid()) {
319 if ($this->is_imagick()) {
320 $this->image->setFirstIterator();
322 $this->image->rotateImage(new ImagickPixel(), -$degrees); // ImageMagick rotates in the opposite direction of imagerotate()
323 } while ($this->image->nextImage());
327 $this->image = imagerotate($this->image,$degrees,0);
328 $this->width = imagesx($this->image);
329 $this->height = imagesy($this->image);
332 public function flip($horiz = true, $vert = false) {
333 if (!$this->is_valid()) {
337 if ($this->is_imagick()) {
338 $this->image->setFirstIterator();
341 $this->image->flipImage();
344 $this->image->flopImage();
346 } while ($this->image->nextImage());
350 $w = imagesx($this->image);
351 $h = imagesy($this->image);
352 $flipped = imagecreate($w, $h);
354 for ($x = 0; $x < $w; $x++) {
355 imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h);
359 for ($y = 0; $y < $h; $y++) {
360 imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1);
363 $this->image = $flipped;
366 public function orient($filename) {
367 if ($this->is_imagick()) {
368 // based off comment on http://php.net/manual/en/imagick.getimageorientation.php
369 $orientation = $this->image->getImageOrientation();
370 switch ($orientation) {
371 case imagick::ORIENTATION_BOTTOMRIGHT:
372 $this->image->rotateimage("#000", 180);
374 case imagick::ORIENTATION_RIGHTTOP:
375 $this->image->rotateimage("#000", 90);
377 case imagick::ORIENTATION_LEFTBOTTOM:
378 $this->image->rotateimage("#000", -90);
382 $this->image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
385 // based off comment on http://php.net/manual/en/function.imagerotate.php
387 if (!$this->is_valid()) {
391 if ( (! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg') ) {
395 $exif = @exif_read_data($filename,null,true);
400 $ort = $exif['IFD0']['Orientation'];
407 case 2: // horizontal flip
411 case 3: // 180 rotate left
415 case 4: // vertical flip
416 $this->flip(false, true);
419 case 5: // vertical flip + 90 rotate right
420 $this->flip(false, true);
424 case 6: // 90 rotate right
428 case 7: // horizontal flip + 90 rotate right
433 case 8: // 90 rotate left
438 // logger('exif: ' . print_r($exif,true));
445 public function scaleImageUp($min) {
446 if (!$this->is_valid()) {
451 $width = $this->getWidth();
452 $height = $this->getHeight();
454 $dest_width = $dest_height = 0;
456 if ((! $width)|| (! $height)) {
460 if ($width < $min && $height < $min) {
461 if ($width > $height) {
463 $dest_height = intval(( $height * $min ) / $width);
465 $dest_width = intval(( $width * $min ) / $height);
469 if ( $width < $min ) {
471 $dest_height = intval(( $height * $min ) / $width);
473 if ( $height < $min ) {
474 $dest_width = intval(( $width * $min ) / $height);
477 $dest_width = $width;
478 $dest_height = $height;
483 if ($this->is_imagick()) {
484 return $this->scaleImage($dest_width,$dest_height);
487 $dest = imagecreatetruecolor( $dest_width, $dest_height );
488 imagealphablending($dest, false);
489 imagesavealpha($dest, true);
490 if ($this->type=='image/png') {
491 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
493 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
495 imagedestroy($this->image);
497 $this->image = $dest;
498 $this->width = imagesx($this->image);
499 $this->height = imagesy($this->image);
504 public function scaleImageSquare($dim) {
505 if (!$this->is_valid()) {
509 if ($this->is_imagick()) {
510 $this->image->setFirstIterator();
512 $this->image->scaleImage($dim, $dim);
513 } while ($this->image->nextImage());
517 $dest = imagecreatetruecolor( $dim, $dim );
518 imagealphablending($dest, false);
519 imagesavealpha($dest, true);
520 if ($this->type=='image/png') {
521 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
523 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height);
525 imagedestroy($this->image);
527 $this->image = $dest;
528 $this->width = imagesx($this->image);
529 $this->height = imagesy($this->image);
533 public function cropImage($max,$x,$y,$w,$h) {
534 if (!$this->is_valid()) {
538 if ($this->is_imagick()) {
539 $this->image->setFirstIterator();
541 $this->image->cropImage($w, $h, $x, $y);
543 * We need to remove the canva,
544 * or the image is not resized to the crop:
545 * http://php.net/manual/en/imagick.cropimage.php#97232
547 $this->image->setImagePage(0, 0, 0, 0);
548 } while ($this->image->nextImage());
549 return $this->scaleImage($max);
552 $dest = imagecreatetruecolor( $max, $max );
553 imagealphablending($dest, false);
554 imagesavealpha($dest, true);
555 if ($this->type=='image/png') {
556 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
558 imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
560 imagedestroy($this->image);
562 $this->image = $dest;
563 $this->width = imagesx($this->image);
564 $this->height = imagesy($this->image);
567 public function saveImage($path) {
568 if (!$this->is_valid()) {
572 $string = $this->imageString();
576 $stamp1 = microtime(true);
577 file_put_contents($path, $string);
578 $a->save_timestamp($stamp1, "file");
581 public function imageString() {
582 if (!$this->is_valid()) {
586 if ($this->is_imagick()) {
588 $this->image = $this->image->deconstructImages();
589 $string = $this->image->getImagesBlob();
597 // Enable interlacing
598 imageinterlace($this->image, true);
600 switch($this->getType()){
602 $quality = get_config('system','png_quality');
603 if ((! $quality) || ($quality > 9)) {
604 $quality = PNG_QUALITY;
606 imagepng($this->image,NULL, $quality);
609 $quality = get_config('system','jpeg_quality');
610 if ((! $quality) || ($quality > 100)) {
611 $quality = JPEG_QUALITY;
613 imagejpeg($this->image,NULL,$quality);
615 $string = ob_get_contents();
623 public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
625 $r = q("SELECT `guid` FROM `photo` WHERE `resource-id` = '%s' AND `guid` != '' LIMIT 1",
628 if (dbm::is_result($r)) {
629 $guid = $r[0]['guid'];
634 $x = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `contact-id` = %d AND `scale` = %d LIMIT 1",
640 if (dbm::is_result($x)) {
641 $r = q("UPDATE `photo`
645 `resource-id` = '%s',
667 dbesc(datetime_convert()),
668 dbesc(datetime_convert()),
669 dbesc(basename($filename)),
670 dbesc($this->getType()),
672 intval($this->getHeight()),
673 intval($this->getWidth()),
674 dbesc(strlen($this->imageString())),
675 dbesc($this->imageString()),
685 $r = q("INSERT INTO `photo`
686 ( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `datasize`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
687 VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s' )",
692 dbesc(datetime_convert()),
693 dbesc(datetime_convert()),
694 dbesc(basename($filename)),
695 dbesc($this->getType()),
697 intval($this->getHeight()),
698 intval($this->getWidth()),
699 dbesc(strlen($this->imageString())),
700 dbesc($this->imageString()),
710 // Update the cached values
711 if ($album != 'Contact Photos') {
712 photo_albums($uid, true);
721 * Guess image mimetype from filename or from Content-Type header
723 * @arg $filename string Image filename
724 * @arg $fromcurl boolean Check Content-Type header from curl request
726 function guess_image_type($filename, $fromcurl=false) {
727 logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
732 $h = explode("\n",$a->get_curl_headers());
734 list($k,$v) = array_map("trim", explode(":", trim($l), 2));
737 if (array_key_exists('Content-Type', $headers))
738 $type = $headers['Content-Type'];
741 // Guessing from extension? Isn't that... dangerous?
742 if (class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
744 * Well, this not much better,
745 * but at least it comes from the data inside the image,
746 * we won't be tricked by a manipulated extension
748 $image = new Imagick($filename);
749 $type = $image->getImageMimeType();
750 $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
752 $ext = pathinfo($filename, PATHINFO_EXTENSION);
753 $types = Photo::supportedTypes();
754 $type = "image/jpeg";
755 foreach ($types as $m=>$e){
762 logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG);
768 * @brief Updates the avatar links in a contact only if needed
770 * @param string $avatar Link to avatar picture
771 * @param int $uid User id of contact owner
772 * @param int $cid Contact id
773 * @param bool $force force picture update
775 * @return array Returns array of the different avatar sizes
777 function update_contact_avatar($avatar,$uid,$cid, $force = false) {
779 $r = q("SELECT `avatar`, `photo`, `thumb`, `micro` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
780 if (!dbm::is_result($r)) {
783 $data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
786 if (($r[0]["avatar"] != $avatar) OR $force) {
787 $photos = import_profile_photo($avatar,$uid,$cid, true);
790 q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
791 dbesc($avatar), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
792 dbesc(datetime_convert()), intval($cid));
800 function import_profile_photo($photo,$uid,$cid, $quit_on_error = false) {
804 $r = q("SELECT `resource-id` FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `scale` = 4 AND `album` = 'Contact Photos' LIMIT 1",
808 if (dbm::is_result($r) && strlen($r[0]['resource-id'])) {
809 $hash = $r[0]['resource-id'];
811 $hash = photo_new_resource();
814 $photo_failure = false;
816 $filename = basename($photo);
817 $img_str = fetch_url($photo,true);
819 if ($quit_on_error AND ($img_str == "")) {
823 $type = guess_image_type($photo,true);
824 $img = new Photo($img_str, $type);
825 if ($img->is_valid()) {
827 $img->scaleImageSquare(175);
829 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4 );
832 $photo_failure = true;
834 $img->scaleImage(80);
836 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5 );
839 $photo_failure = true;
841 $img->scaleImage(48);
843 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6 );
846 $photo_failure = true;
849 $photo = $a->get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt();
850 $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt();
851 $micro = $a->get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt();
853 $photo_failure = true;
856 if ($photo_failure AND $quit_on_error) {
860 if ($photo_failure) {
861 $photo = $a->get_baseurl() . '/images/person-175.jpg';
862 $thumb = $a->get_baseurl() . '/images/person-80.jpg';
863 $micro = $a->get_baseurl() . '/images/person-48.jpg';
866 return(array($photo,$thumb,$micro));
870 function get_photo_info($url) {
873 $data = Cache::get($url);
875 if (is_null($data) OR !$data) {
876 $img_str = fetch_url($url, true, $redirects, 4);
877 $filesize = strlen($img_str);
879 if (function_exists("getimagesizefromstring")) {
880 $data = getimagesizefromstring($img_str);
882 $tempfile = tempnam(get_temppath(), "cache");
885 $stamp1 = microtime(true);
886 file_put_contents($tempfile, $img_str);
887 $a->save_timestamp($stamp1, "file");
889 $data = getimagesize($tempfile);
894 $data["size"] = $filesize;
897 Cache::set($url, $data);
903 function scale_image($width, $height, $max) {
905 $dest_width = $dest_height = 0;
907 if ((!$width) || (!$height)) {
911 if ($width > $max && $height > $max) {
913 // very tall image (greater than 16:9)
914 // constrain the width - let the height float.
916 if ((($height * 9) / 16) > $width) {
918 $dest_height = intval(( $height * $max ) / $width);
919 } elseif ($width > $height) {
920 // else constrain both dimensions
922 $dest_height = intval(( $height * $max ) / $width);
924 $dest_width = intval(( $width * $max ) / $height);
928 if ( $width > $max ) {
930 $dest_height = intval(( $height * $max ) / $width);
932 if ( $height > $max ) {
934 // very tall image (greater than 16:9)
935 // but width is OK - don't do anything
937 if ((($height * 9) / 16) > $width) {
938 $dest_width = $width;
939 $dest_height = $height;
941 $dest_width = intval(( $width * $max ) / $height);
945 $dest_width = $width;
946 $dest_height = $height;
950 return array("width" => $dest_width, "height" => $dest_height);
953 function store_photo($a, $uid, $imagedata = "", $url = "") {
954 $r = q("SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
955 WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1",
958 if (!dbm::is_result($r)) {
959 logger("Can't detect user data for uid ".$uid, LOGGER_DEBUG);
963 $page_owner_nick = $r[0]['nickname'];
966 /// $default_cid = $r[0]['id'];
967 /// $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
969 if ((strlen($imagedata) == 0) AND ($url == "")) {
970 logger("No image data and no url provided", LOGGER_DEBUG);
972 } elseif (strlen($imagedata) == 0) {
973 logger("Uploading picture from ".$url, LOGGER_DEBUG);
975 $stamp1 = microtime(true);
976 $imagedata = @file_get_contents($url);
977 $a->save_timestamp($stamp1, "file");
980 $maximagesize = get_config('system','maximagesize');
982 if (($maximagesize) && (strlen($imagedata) > $maximagesize)) {
983 logger("Image exceeds size limit of ".$maximagesize, LOGGER_DEBUG);
988 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
992 $limit = service_class_fetch($uid,'photo_upload_limit');
994 if (($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
995 logger("Image exceeds personal limit of uid ".$uid, LOGGER_DEBUG);
1000 $tempfile = tempnam(get_temppath(), "cache");
1002 $stamp1 = microtime(true);
1003 file_put_contents($tempfile, $imagedata);
1004 $a->save_timestamp($stamp1, "file");
1006 $data = getimagesize($tempfile);
1008 if (!isset($data["mime"])) {
1010 logger("File is no picture", LOGGER_DEBUG);
1014 $ph = new Photo($imagedata, $data["mime"]);
1016 if (!$ph->is_valid()) {
1018 logger("Picture is no valid picture", LOGGER_DEBUG);
1022 $ph->orient($tempfile);
1025 $max_length = get_config('system','max_image_length');
1026 if (! $max_length) {
1027 $max_length = MAX_IMAGE_LENGTH;
1029 if ($max_length > 0) {
1030 $ph->scaleImage($max_length);
1033 $width = $ph->getWidth();
1034 $height = $ph->getHeight();
1036 $hash = photo_new_resource();
1040 // Pictures are always public by now
1041 //$defperm = '<'.$default_cid.'>';
1045 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 0, 0, $defperm);
1048 logger("Picture couldn't be stored", LOGGER_DEBUG);
1052 $image = array("page" => $a->get_baseurl().'/photos/'.$page_owner_nick.'/image/'.$hash,
1053 "full" => $a->get_baseurl()."/photo/{$hash}-0.".$ph->getExt());
1055 if ($width > 800 || $height > 800) {
1056 $image["large"] = $a->get_baseurl()."/photo/{$hash}-0.".$ph->getExt();
1059 if ($width > 640 || $height > 640) {
1060 $ph->scaleImage(640);
1061 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm);
1063 $image["medium"] = $a->get_baseurl()."/photo/{$hash}-1.".$ph->getExt();
1067 if ($width > 320 || $height > 320) {
1068 $ph->scaleImage(320);
1069 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm);
1071 $image["small"] = $a->get_baseurl()."/photo/{$hash}-2.".$ph->getExt();
1075 if ($width > 160 AND $height > 160) {
1079 $min = $ph->getWidth();
1081 $x = ($min - 160) / 2;
1084 if ($ph->getHeight() < $min) {
1085 $min = $ph->getHeight();
1087 $y = ($min - 160) / 2;
1092 $ph->cropImage(160, $x, $y, $min, $min);
1094 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
1096 $image["thumb"] = $a->get_baseurl()."/photo/{$hash}-3.".$ph->getExt();
1100 // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
1101 $image["preview"] = $image["full"];
1103 // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
1104 //if (isset($image["thumb"]))
1105 // $image["preview"] = $image["thumb"];
1107 // Unsure, if this should be activated or deactivated
1108 //if (isset($image["small"]))
1109 // $image["preview"] = $image["small"];
1111 if (isset($image["medium"])) {
1112 $image["preview"] = $image["medium"];