3 * @file include/Photo.php
4 * @brief This file contains the Photo class for image processing
9 require_once("include/photos.php");
16 * Put back gd stuff, not everybody have Imagick
26 * @brief supported mimetypes and corresponding file extensions
28 static function supportedTypes() {
29 if (class_exists('Imagick')) {
31 // Imagick::queryFormats won't help us a lot there...
32 // At least, not yet, other parts of friendica uses this array
34 'image/jpeg' => 'jpg',
40 $t['image/jpeg'] ='jpg';
41 if (imagetypes() & IMG_PNG) {
42 $t['image/png'] = 'png';
49 public function __construct($data, $type=null) {
50 $this->imagick = class_exists('Imagick');
51 $this->types = $this->supportedTypes();
52 if (!array_key_exists($type, $this->types)){
57 if ($this->is_imagick() && $this->load_data($data)) {
60 // Failed to load with Imagick, fallback
61 $this->imagick = false;
63 return $this->load_data($data);
66 public function __destruct() {
68 if ($this->is_imagick()) {
69 $this->image->clear();
70 $this->image->destroy();
73 imagedestroy($this->image);
77 public function is_imagick() {
78 return $this->imagick;
82 * @brief Maps Mime types to Imagick formats
83 * @return arr With with image formats (mime type as key)
85 public function get_FormatsMap() {
87 'image/jpeg' => 'JPG',
94 private function load_data($data) {
95 if ($this->is_imagick()) {
96 $this->image = new Imagick();
98 $this->image->readImageBlob($data);
99 } catch (Exception $e) {
100 // Imagick couldn't use the data
105 * Setup the image to the format it will be saved to
107 $map = $this->get_FormatsMap();
108 $format = $map[$type];
109 $this->image->setFormat($format);
111 // Always coalesce, if it is not a multi-frame image it won't hurt anyway
112 $this->image = $this->image->coalesceImages();
115 * setup the compression here, so we'll do it only once
117 switch($this->getType()){
119 $quality = get_config('system', 'png_quality');
120 if ((! $quality) || ($quality > 9)) {
121 $quality = PNG_QUALITY;
124 * From http://www.imagemagick.org/script/command-line-options.php#quality:
126 * 'For the MNG and PNG image formats, the quality value sets
127 * the zlib compression level (quality / 10) and filter-type (quality % 10).
128 * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering,
129 * unless the image has a color map, in which case it means compression level 7 with no PNG filtering'
131 $quality = $quality * 10;
132 $this->image->setCompressionQuality($quality);
135 $quality = get_config('system', 'jpeg_quality');
136 if ((! $quality) || ($quality > 100)) {
137 $quality = JPEG_QUALITY;
139 $this->image->setCompressionQuality($quality);
142 // The 'width' and 'height' properties are only used by non-Imagick routines.
143 $this->width = $this->image->getImageWidth();
144 $this->height = $this->image->getImageHeight();
150 $this->valid = false;
151 $this->image = @imagecreatefromstring($data);
152 if ($this->image !== false) {
153 $this->width = imagesx($this->image);
154 $this->height = imagesy($this->image);
156 imagealphablending($this->image, false);
157 imagesavealpha($this->image, true);
165 public function is_valid() {
166 if ($this->is_imagick()) {
167 return ($this->image !== false);
172 public function getWidth() {
173 if (!$this->is_valid()) {
177 if ($this->is_imagick()) {
178 return $this->image->getImageWidth();
183 public function getHeight() {
184 if (!$this->is_valid()) {
188 if ($this->is_imagick()) {
189 return $this->image->getImageHeight();
191 return $this->height;
194 public function getImage() {
195 if (!$this->is_valid()) {
199 if ($this->is_imagick()) {
201 $this->image = $this->image->deconstructImages();
207 public function getType() {
208 if (!$this->is_valid()) {
215 public function getExt() {
216 if (!$this->is_valid()) {
220 return $this->types[$this->getType()];
223 public function scaleImage($max) {
224 if (!$this->is_valid()) {
228 $width = $this->getWidth();
229 $height = $this->getHeight();
231 $dest_width = $dest_height = 0;
233 if ((! $width)|| (! $height)) {
237 if ($width > $max && $height > $max) {
239 // very tall image (greater than 16:9)
240 // constrain the width - let the height float.
242 if ((($height * 9) / 16) > $width) {
244 $dest_height = intval(($height * $max) / $width);
245 } elseif ($width > $height) {
246 // else constrain both dimensions
248 $dest_height = intval(($height * $max) / $width);
250 $dest_width = intval(($width * $max) / $height);
256 $dest_height = intval(($height * $max) / $width);
258 if ($height > $max) {
260 // very tall image (greater than 16:9)
261 // but width is OK - don't do anything
263 if ((($height * 9) / 16) > $width) {
264 $dest_width = $width;
265 $dest_height = $height;
267 $dest_width = intval(($width * $max) / $height);
271 $dest_width = $width;
272 $dest_height = $height;
278 if ($this->is_imagick()) {
280 * If it is not animated, there will be only one iteration here,
281 * so don't bother checking
283 // Don't forget to go back to the first frame
284 $this->image->setFirstIterator();
287 // FIXME - implement horizantal bias for scaling as in followin GD functions
288 // to allow very tall images to be constrained only horizontally.
290 $this->image->scaleImage($dest_width, $dest_height);
291 } while ($this->image->nextImage());
293 // These may not be necessary any more
294 $this->width = $this->image->getImageWidth();
295 $this->height = $this->image->getImageHeight();
301 $dest = imagecreatetruecolor($dest_width, $dest_height);
302 imagealphablending($dest, false);
303 imagesavealpha($dest, true);
304 if ($this->type=='image/png') {
305 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
307 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
309 imagedestroy($this->image);
311 $this->image = $dest;
312 $this->width = imagesx($this->image);
313 $this->height = imagesy($this->image);
316 public function rotate($degrees) {
317 if (!$this->is_valid()) {
321 if ($this->is_imagick()) {
322 $this->image->setFirstIterator();
324 $this->image->rotateImage(new ImagickPixel(), -$degrees); // ImageMagick rotates in the opposite direction of imagerotate()
325 } while ($this->image->nextImage());
329 $this->image = imagerotate($this->image,$degrees,0);
330 $this->width = imagesx($this->image);
331 $this->height = imagesy($this->image);
334 public function flip($horiz = true, $vert = false) {
335 if (!$this->is_valid()) {
339 if ($this->is_imagick()) {
340 $this->image->setFirstIterator();
343 $this->image->flipImage();
346 $this->image->flopImage();
348 } while ($this->image->nextImage());
352 $w = imagesx($this->image);
353 $h = imagesy($this->image);
354 $flipped = imagecreate($w, $h);
356 for ($x = 0; $x < $w; $x++) {
357 imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h);
361 for ($y = 0; $y < $h; $y++) {
362 imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1);
365 $this->image = $flipped;
368 public function orient($filename) {
369 if ($this->is_imagick()) {
370 // based off comment on http://php.net/manual/en/imagick.getimageorientation.php
371 $orientation = $this->image->getImageOrientation();
372 switch ($orientation) {
373 case imagick::ORIENTATION_BOTTOMRIGHT:
374 $this->image->rotateimage("#000", 180);
376 case imagick::ORIENTATION_RIGHTTOP:
377 $this->image->rotateimage("#000", 90);
379 case imagick::ORIENTATION_LEFTBOTTOM:
380 $this->image->rotateimage("#000", -90);
384 $this->image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
387 // based off comment on http://php.net/manual/en/function.imagerotate.php
389 if (!$this->is_valid()) {
393 if ((!function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) {
397 $exif = @exif_read_data($filename,null,true);
402 $ort = $exif['IFD0']['Orientation'];
409 case 2: // horizontal flip
413 case 3: // 180 rotate left
417 case 4: // vertical flip
418 $this->flip(false, true);
421 case 5: // vertical flip + 90 rotate right
422 $this->flip(false, true);
426 case 6: // 90 rotate right
430 case 7: // horizontal flip + 90 rotate right
435 case 8: // 90 rotate left
440 // logger('exif: ' . print_r($exif,true));
447 public function scaleImageUp($min) {
448 if (!$this->is_valid()) {
453 $width = $this->getWidth();
454 $height = $this->getHeight();
456 $dest_width = $dest_height = 0;
458 if ((!$width)|| (!$height)) {
462 if ($width < $min && $height < $min) {
463 if ($width > $height) {
465 $dest_height = intval(($height * $min) / $width);
467 $dest_width = intval(($width * $min) / $height);
473 $dest_height = intval(($height * $min) / $width);
475 if ($height < $min) {
476 $dest_width = intval(($width * $min) / $height);
479 $dest_width = $width;
480 $dest_height = $height;
485 if ($this->is_imagick()) {
486 return $this->scaleImage($dest_width, $dest_height);
489 $dest = imagecreatetruecolor($dest_width, $dest_height);
490 imagealphablending($dest, false);
491 imagesavealpha($dest, true);
492 if ($this->type=='image/png') {
493 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
495 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
497 imagedestroy($this->image);
499 $this->image = $dest;
500 $this->width = imagesx($this->image);
501 $this->height = imagesy($this->image);
506 public function scaleImageSquare($dim) {
507 if (!$this->is_valid()) {
511 if ($this->is_imagick()) {
512 $this->image->setFirstIterator();
514 $this->image->scaleImage($dim, $dim);
515 } while ($this->image->nextImage());
519 $dest = imagecreatetruecolor($dim, $dim);
520 imagealphablending($dest, false);
521 imagesavealpha($dest, true);
522 if ($this->type=='image/png') {
523 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
525 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height);
527 imagedestroy($this->image);
529 $this->image = $dest;
530 $this->width = imagesx($this->image);
531 $this->height = imagesy($this->image);
535 public function cropImage($max, $x, $y, $w, $h) {
536 if (!$this->is_valid()) {
540 if ($this->is_imagick()) {
541 $this->image->setFirstIterator();
543 $this->image->cropImage($w, $h, $x, $y);
545 * We need to remove the canva,
546 * or the image is not resized to the crop:
547 * http://php.net/manual/en/imagick.cropimage.php#97232
549 $this->image->setImagePage(0, 0, 0, 0);
550 } while ($this->image->nextImage());
551 return $this->scaleImage($max);
554 $dest = imagecreatetruecolor($max, $max);
555 imagealphablending($dest, false);
556 imagesavealpha($dest, true);
557 if ($this->type=='image/png') {
558 imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
560 imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
562 imagedestroy($this->image);
564 $this->image = $dest;
565 $this->width = imagesx($this->image);
566 $this->height = imagesy($this->image);
569 public function saveImage($path) {
570 if (!$this->is_valid()) {
574 $string = $this->imageString();
578 $stamp1 = microtime(true);
579 file_put_contents($path, $string);
580 $a->save_timestamp($stamp1, "file");
583 public function imageString() {
584 if (!$this->is_valid()) {
588 if ($this->is_imagick()) {
590 $this->image = $this->image->deconstructImages();
591 $string = $this->image->getImagesBlob();
599 // Enable interlacing
600 imageinterlace($this->image, true);
602 switch($this->getType()){
604 $quality = get_config('system', 'png_quality');
605 if ((!$quality) || ($quality > 9)) {
606 $quality = PNG_QUALITY;
608 imagepng($this->image, null, $quality);
611 $quality = get_config('system', 'jpeg_quality');
612 if ((!$quality) || ($quality > 100)) {
613 $quality = JPEG_QUALITY;
615 imagejpeg($this->image, null, $quality);
617 $string = ob_get_contents();
625 public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
627 $r = q("SELECT `guid` FROM `photo` WHERE `resource-id` = '%s' AND `guid` != '' LIMIT 1",
630 if (dbm::is_result($r)) {
631 $guid = $r[0]['guid'];
636 $x = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `contact-id` = %d AND `scale` = %d LIMIT 1",
642 if (dbm::is_result($x)) {
643 $r = q("UPDATE `photo`
647 `resource-id` = '%s',
669 dbesc(datetime_convert()),
670 dbesc(datetime_convert()),
671 dbesc(basename($filename)),
672 dbesc($this->getType()),
674 intval($this->getHeight()),
675 intval($this->getWidth()),
676 dbesc(strlen($this->imageString())),
677 dbesc($this->imageString()),
687 $r = q("INSERT INTO `photo`
688 (`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`)
689 VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s')",
694 dbesc(datetime_convert()),
695 dbesc(datetime_convert()),
696 dbesc(basename($filename)),
697 dbesc($this->getType()),
699 intval($this->getHeight()),
700 intval($this->getWidth()),
701 dbesc(strlen($this->imageString())),
702 dbesc($this->imageString()),
718 * Guess image mimetype from filename or from Content-Type header
720 * @arg $filename string Image filename
721 * @arg $fromcurl boolean Check Content-Type header from curl request
723 function guess_image_type($filename, $fromcurl=false) {
724 logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
729 $h = explode("\n",$a->get_curl_headers());
731 list($k,$v) = array_map("trim", explode(":", trim($l), 2));
734 if (array_key_exists('Content-Type', $headers))
735 $type = $headers['Content-Type'];
738 // Guessing from extension? Isn't that... dangerous?
739 if (class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
741 * Well, this not much better,
742 * but at least it comes from the data inside the image,
743 * we won't be tricked by a manipulated extension
745 $image = new Imagick($filename);
746 $type = $image->getImageMimeType();
747 $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
749 $ext = pathinfo($filename, PATHINFO_EXTENSION);
750 $types = Photo::supportedTypes();
751 $type = "image/jpeg";
752 foreach ($types as $m => $e){
759 logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG);
765 * @brief Updates the avatar links in a contact only if needed
767 * @param string $avatar Link to avatar picture
768 * @param int $uid User id of contact owner
769 * @param int $cid Contact id
770 * @param bool $force force picture update
772 * @return array Returns array of the different avatar sizes
774 function update_contact_avatar($avatar, $uid, $cid, $force = false) {
776 $r = q("SELECT `avatar`, `photo`, `thumb`, `micro` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
777 if (!dbm::is_result($r)) {
780 $data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
783 if (($r[0]["avatar"] != $avatar) OR $force) {
784 $photos = import_profile_photo($avatar, $uid, $cid, true);
787 q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
788 dbesc($avatar), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
789 dbesc(datetime_convert()), intval($cid));
797 function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) {
799 $r = q("SELECT `resource-id` FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `scale` = 4 AND `album` = 'Contact Photos' LIMIT 1",
803 if (dbm::is_result($r) && strlen($r[0]['resource-id'])) {
804 $hash = $r[0]['resource-id'];
806 $hash = photo_new_resource();
809 $photo_failure = false;
811 $filename = basename($photo);
812 $img_str = fetch_url($photo, true);
814 if ($quit_on_error AND ($img_str == "")) {
818 $type = guess_image_type($photo, true);
819 $img = new Photo($img_str, $type);
820 if ($img->is_valid()) {
822 $img->scaleImageSquare(175);
824 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4);
827 $photo_failure = true;
829 $img->scaleImage(80);
831 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5);
834 $photo_failure = true;
836 $img->scaleImage(48);
838 $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6);
841 $photo_failure = true;
844 $photo = App::get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt();
845 $thumb = App::get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt();
846 $micro = App::get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt();
848 $photo_failure = true;
851 if ($photo_failure AND $quit_on_error) {
855 if ($photo_failure) {
856 $photo = App::get_baseurl() . '/images/person-175.jpg';
857 $thumb = App::get_baseurl() . '/images/person-80.jpg';
858 $micro = App::get_baseurl() . '/images/person-48.jpg';
861 return(array($photo,$thumb,$micro));
865 function get_photo_info($url) {
868 $data = Cache::get($url);
870 if (is_null($data) OR !$data OR !is_array($data)) {
871 $img_str = fetch_url($url, true, $redirects, 4);
872 $filesize = strlen($img_str);
874 if (function_exists("getimagesizefromstring")) {
875 $data = getimagesizefromstring($img_str);
877 $tempfile = tempnam(get_temppath(), "cache");
880 $stamp1 = microtime(true);
881 file_put_contents($tempfile, $img_str);
882 $a->save_timestamp($stamp1, "file");
884 $data = getimagesize($tempfile);
889 $data["size"] = $filesize;
892 Cache::set($url, $data);
898 function scale_image($width, $height, $max) {
900 $dest_width = $dest_height = 0;
902 if ((!$width) || (!$height)) {
906 if ($width > $max && $height > $max) {
908 // very tall image (greater than 16:9)
909 // constrain the width - let the height float.
911 if ((($height * 9) / 16) > $width) {
913 $dest_height = intval(($height * $max) / $width);
914 } elseif ($width > $height) {
915 // else constrain both dimensions
917 $dest_height = intval(($height * $max) / $width);
919 $dest_width = intval(($width * $max) / $height);
925 $dest_height = intval(($height * $max) / $width);
927 if ($height > $max) {
929 // very tall image (greater than 16:9)
930 // but width is OK - don't do anything
932 if ((($height * 9) / 16) > $width) {
933 $dest_width = $width;
934 $dest_height = $height;
936 $dest_width = intval(($width * $max) / $height);
940 $dest_width = $width;
941 $dest_height = $height;
945 return array("width" => $dest_width, "height" => $dest_height);
948 function store_photo(App $a, $uid, $imagedata = "", $url = "") {
949 $r = q("SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
950 WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1",
953 if (!dbm::is_result($r)) {
954 logger("Can't detect user data for uid ".$uid, LOGGER_DEBUG);
958 $page_owner_nick = $r[0]['nickname'];
961 /// $default_cid = $r[0]['id'];
962 /// $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
964 if ((strlen($imagedata) == 0) AND ($url == "")) {
965 logger("No image data and no url provided", LOGGER_DEBUG);
967 } elseif (strlen($imagedata) == 0) {
968 logger("Uploading picture from ".$url, LOGGER_DEBUG);
970 $stamp1 = microtime(true);
971 $imagedata = @file_get_contents($url);
972 $a->save_timestamp($stamp1, "file");
975 $maximagesize = get_config('system', 'maximagesize');
977 if (($maximagesize) && (strlen($imagedata) > $maximagesize)) {
978 logger("Image exceeds size limit of ".$maximagesize, LOGGER_DEBUG);
983 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
987 $limit = service_class_fetch($uid,'photo_upload_limit');
989 if (($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
990 logger("Image exceeds personal limit of uid ".$uid, LOGGER_DEBUG);
995 $tempfile = tempnam(get_temppath(), "cache");
997 $stamp1 = microtime(true);
998 file_put_contents($tempfile, $imagedata);
999 $a->save_timestamp($stamp1, "file");
1001 $data = getimagesize($tempfile);
1003 if (!isset($data["mime"])) {
1005 logger("File is no picture", LOGGER_DEBUG);
1009 $ph = new Photo($imagedata, $data["mime"]);
1011 if (!$ph->is_valid()) {
1013 logger("Picture is no valid picture", LOGGER_DEBUG);
1017 $ph->orient($tempfile);
1020 $max_length = get_config('system', 'max_image_length');
1021 if (! $max_length) {
1022 $max_length = MAX_IMAGE_LENGTH;
1024 if ($max_length > 0) {
1025 $ph->scaleImage($max_length);
1028 $width = $ph->getWidth();
1029 $height = $ph->getHeight();
1031 $hash = photo_new_resource();
1035 // Pictures are always public by now
1036 //$defperm = '<'.$default_cid.'>';
1040 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 0, 0, $defperm);
1043 logger("Picture couldn't be stored", LOGGER_DEBUG);
1047 $image = array("page" => App::get_baseurl().'/photos/'.$page_owner_nick.'/image/'.$hash,
1048 "full" => App::get_baseurl()."/photo/{$hash}-0.".$ph->getExt());
1050 if ($width > 800 || $height > 800) {
1051 $image["large"] = App::get_baseurl()."/photo/{$hash}-0.".$ph->getExt();
1054 if ($width > 640 || $height > 640) {
1055 $ph->scaleImage(640);
1056 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm);
1058 $image["medium"] = App::get_baseurl()."/photo/{$hash}-1.".$ph->getExt();
1062 if ($width > 320 || $height > 320) {
1063 $ph->scaleImage(320);
1064 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm);
1066 $image["small"] = App::get_baseurl()."/photo/{$hash}-2.".$ph->getExt();
1070 if ($width > 160 AND $height > 160) {
1074 $min = $ph->getWidth();
1076 $x = ($min - 160) / 2;
1079 if ($ph->getHeight() < $min) {
1080 $min = $ph->getHeight();
1082 $y = ($min - 160) / 2;
1087 $ph->cropImage(160, $x, $y, $min, $min);
1089 $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
1091 $image["thumb"] = App::get_baseurl()."/photo/{$hash}-3.".$ph->getExt();
1095 // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
1096 $image["preview"] = $image["full"];
1098 // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
1099 //if (isset($image["thumb"]))
1100 // $image["preview"] = $image["thumb"];
1102 // Unsure, if this should be activated or deactivated
1103 //if (isset($image["small"]))
1104 // $image["preview"] = $image["small"];
1106 if (isset($image["medium"])) {
1107 $image["preview"] = $image["medium"];