+ /**
+ * store photo metadata in db and binary with preview photos in default backend
+ *
+ * @param Image $image Image object with data
+ * @param integer $uid User ID
+ * @param string $resource_id Resource ID
+ * @param string $filename Filename
+ * @param integer $filesize Filesize
+ * @param string $album Album name
+ * @param string $description Photo caption
+ * @param string $allow_cid Permissions, allowed contacts
+ * @param string $allow_gid Permissions, allowed circles
+ * @param string $deny_cid Permissions, denied contacts
+ * @param string $deny_gid Permissions, denied circles
+ *
+ * @return integer preview photo size
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ public static function storeWithPreview(Image $image, int $uid, string $resource_id, string $filename, int $filesize, string $album, string $description, string $allow_cid, string $allow_gid, string $deny_cid, string $deny_gid): int
+ {
+ $image = self::resizeToFileSize($image, Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')));
+
+ $width = $image->getWidth();
+ $height = $image->getHeight();
+ $preview = 0;
+
+ $result = self::store($image, $uid, 0, $resource_id, $filename, $album, 0, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $description);
+ if (!$result) {
+ Logger::warning('Photo could not be stored', ['uid' => $uid, 'resource_id' => $resource_id, 'filename' => $filename, 'album' => $album]);
+ return -1;
+ }
+
+ if ($width > 640 || $height > 640) {
+ $image->scaleDown(640);
+ }
+
+ if ($width > 320 || $height > 320) {
+ $result = self::store($image, $uid, 0, $resource_id, $filename, $album, 1, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $description);
+ if ($result) {
+ $preview = 1;
+ }
+ $image->scaleDown(320);
+ $result = self::store($image, $uid, 0, $resource_id, $filename, $album, 2, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $description);
+ if ($result && ($preview == 0)) {
+ $preview = 2;
+ }
+ }
+ return $preview;
+ }
+