Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cordova-plugin-photo-library
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cep-plugins
cordova-plugin-photo-library
Commits
0036c152
Commit
0036c152
authored
8 years ago
by
viskin
Browse files
Options
Downloads
Patches
Plain Diff
added image2DataURL
parent
4ba79f4e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+4
-0
4 additions, 0 deletions
README.md
src/ios/PhotoLibrary.swift
+25
-1
25 additions, 1 deletion
src/ios/PhotoLibrary.swift
with
29 additions
and
1 deletion
README.md
0 → 100644
+
4
−
0
View file @
0036c152
Parts are based on
-
https://github.com/ryouaki/Cordova-Plugin-Photos
-
https://github.com/subitolabs/cordova-gallery-api
This diff is collapsed.
Click to expand it.
src/ios/PhotoLibrary.swift
+
25
−
1
View file @
0036c152
...
...
@@ -39,6 +39,30 @@ import Foundation
dateFormatter
.
dateFormat
=
"yyyy-MM-dd'T'HH:mm:ss.SSS"
}
private
func
image2DataURL
(
image
:
UIImage
)
->
String
?
{
var
imageData
:
NSData
?
var
mimeType
:
String
if
(
imageHasAlpha
(
image
)){
imageData
=
UIImagePNGRepresentation
(
image
)
mimeType
=
"image/png"
}
else
{
imageData
=
UIImageJPEGRepresentation
(
image
,
1.0
)
mimeType
=
"image/jpeg"
}
if
(
imageData
!=
nil
)
{
let
encodedString
=
imageData
?
.
base64EncodedStringWithOptions
(
NSDataBase64EncodingOptions
(
rawValue
:
0
))
if
(
encodedString
!=
nil
)
{
return
String
(
format
:
"data:%@;base64,%@"
,
mimeType
,
encodedString
!
)
}
}
return
nil
}
private
func
imageHasAlpha
(
image
:
UIImage
)
->
Bool
{
let
alphaInfo
=
CGImageGetAlphaInfo
(
image
.
CGImage
)
return
alphaInfo
==
.
First
||
alphaInfo
==
.
Last
||
alphaInfo
==
.
PremultipliedFirst
||
alphaInfo
==
.
PremultipliedLast
}
// Will sort by creation date
func
getPhotos
(
command
:
CDVInvokedUrlCommand
)
{
dispatch_async
(
dispatch_get_main_queue
(),
{
...
...
@@ -66,7 +90,7 @@ import Foundation
resultImage
[
"id"
]
=
asset
.
localIdentifier
resultImage
[
"filename"
]
=
imageURL
?
.
pathComponents
?
.
last
resultImage
[
"nativeUrl"
]
=
imageURL
?
.
absoluteString
//TODO: in Swift 3, use JSONRepresentable
resultImage
[
"url"
]
=
nil
//TODO: convert to data ur
l
resultImage
[
"url"
]
=
image
!=
nil
?
self
.
image2DataURL
(
image
!
)
:
ni
l
resultImage
[
"width"
]
=
asset
.
pixelWidth
resultImage
[
"height"
]
=
asset
.
pixelHeight
resultImage
[
"creationDate"
]
=
self
.
dateFormatter
.
stringFromDate
(
asset
.
creationDate
!
)
//TODO: in Swift 3, use JSONRepresentable
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment