You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've used PNG on local mac files. usually they arrive via drag/drop & I call PNG with the file path.
Users may also drag in a link or remote image, and my app receives a URL. the swift Data object easily represents remote data - it basically does a curl. Using PNG's stream api & a little glue, my app now treats remote links the same as local files. worked on the first try.
very clean.
/// glue for URL Data to PNG stream
publicstructURLDataSource:PNG.BytestreamSource{letdata:Datavarposition:Int=0publicinit(data:Data){self.data = data
}publicmutatingfunc read(count capacity:Int)->[UInt8]?{guard position + capacity <= data.count else{returnnil}letrange= position..<(position + capacity)
position += capacity
returnArray(data[range])}publicvarcount:Int?{return data.count
}}
// remote data extraction
staticfunc extractMetadata(from url:URL)->MetadataSource?{
// this basically does a curl
iflet data =tryData(contentsOf: url){varsource=URLDataSource(data: data)guardlet image =try?PNG.Image.decompress(stream:&source)else{returnMetadataSource(metadata:[:], sourceLocation:.unknown)}returnprocessImage(image)}returnnil}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I've used PNG on local mac files. usually they arrive via drag/drop & I call PNG with the file path.
Users may also drag in a link or remote image, and my app receives a URL. the swift
Data
object easily represents remote data - it basically does a curl. Using PNG's stream api & a little glue, my app now treats remote links the same as local files. worked on the first try.very clean.
Beta Was this translation helpful? Give feedback.
All reactions