+ /**
+ * Construct a photo array for a given image data string
+ *
+ * @param string $image_data Image data
+ * @param string $mimetype Image mime type. Is guessed by file name when empty.
+ *
+ * @return array
+ * @throws \Exception
+ */
+ public static function createPhotoForImageData(string $image_data, string $mimetype = ''): array
+ {
+ $fields = self::getFields();
+ $values = array_fill(0, count($fields), '');
+
+ $photo = array_combine($fields, $values);
+ $photo['data'] = $image_data;
+ $photo['type'] = $mimetype ?: Images::getMimeTypeByData($image_data);
+ $photo['cacheable'] = false;
+
+ return $photo;
+ }
+