0

I'm writing a Swift Server that accepts and saves a base64 String which has encoded a UIImage via UIImageJPEGRepresentation (so I can compress it). This string is then sent as JSON, where it is saved to a Swift Cloudant database. However, the server doesn't have access to UIKit, so I can't refer to a UIImage in it's code to decode it back into a picture. Is there a way to turn the String back into a picture without using UIImage?

Pure Swift would be the best option, but I don't know if it's actually possible. My server is a Kitura one, hosted on IBM Bluemix. Thank you!

(The goal is to show the picture on a webpage.)

S. Matsepura
  • 1,673
  • 1
  • 17
  • 24
Kye
  • 3
  • 1
  • 3
  • If you're displaying the picture on a website, then your web framework should have some means of deserializing the image. How are you creating the other contents for the site? – jscs Aug 23 '17 at 12:33
  • I've been able to turn `Data` into an `Image` object using a combination of the [FileUtils](https://github.com/oarrabi/FileUtils.git) and [SwiftGD](https://github.com/twostraws/SwiftGD.git) packages. SwiftGD does depend on [Cgd](https://github.com/twostraws/Cgd.git), but its otherwise pure Swift. You can see an example implementation at [kitura-image-server](https://github.com/udacity/kitura-image-server) — look specifically at the main.swift file. – jarrodparkes Aug 26 '17 at 21:28

1 Answers1

0

I don't know if it can help but as you need to show this image on a website I, in an application where I need to show a webview with a image,used this (in the .html file containing my webpage)

<img src="data:image/png;base64,#IMAGE_STRING#">

and when I run the application the "#IMAGE_STRING#" is replaced by the base64 string containing the image , the result is : my image is showing perfectly in the webpage

Leo
  • 68
  • 9