Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

get color of locale image #2

Open
Psiiirus opened this issue Oct 22, 2019 · 13 comments
Open

get color of locale image #2

Psiiirus opened this issue Oct 22, 2019 · 13 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers work in progress

Comments

@Psiiirus
Copy link

Hiya,
is it possible to extent this lib to also extract colors of locale images?

Cheers,
Toni

@Psiiirus
Copy link
Author

I'm a total noob in swift so it took me a while to get a version working on iOS with asset-library:// URL
Maybe this code can help to make a fast implemention?
Not doing a PR because the lack of Android support

//
//  DominantColor.swift
//  RNDominant Color
//
//  Created by Matin ZD on 7/11/1398 AP.
//  Copyright © 1398 Facebook. All rights reserved.
//

import Foundation
import UIKit
import Photos // use the Photos Framework

@objc(RNDominantColor)
class RNDominantColor : NSObject {
  
    @objc static func requiresMainQueueSetup() -> Bool {
        return false
    }
    
    @objc func getColorFromURI(_ imageURI: String,callback successCallback: @escaping RCTResponseSenderBlock ) {
        let url = URL(string: imageURI as String)
        
        let fetchResult = PHAsset.fetchAssets(withALAssetURLs: [url!], options: nil)
        if let phAsset = fetchResult.firstObject {
            PHImageManager.default().requestImageData(for: phAsset, options: nil) {
                (imageData, dataURI, orientation, info) -> Void in
                if let imageDataExists = imageData {
                    guard let colors = UIImage(data: imageDataExists)?.getColors() else {
                      return successCallback(["#00000000", "#00000000", "#00000000", "#00000000", "#00000000"])
                    }
                    successCallback([
                      colors.primaryHex,
                      colors.secondaryHex,
                      colors.backgroundHex,
                      colors.detailHex
                    ])
                }
            }
        } else {
          return successCallback(["#00000000", "#00000000", "#00000000", "#00000000", "#00000000"])
        }
    }

    @objc func getColorFromURL(_ imageURL: NSString,callback successCallback: RCTResponseSenderBlock ) {
        let url = URL(string: imageURL as String)
        let data = try? Data(contentsOf: url!)
        guard let colors = UIImage(data: data!)?.getColors() else {
          return successCallback(["#00000000", "#00000000", "#00000000", "#00000000", "#00000000"])
        }
        successCallback([
          colors.primaryHex,
          colors.secondaryHex,
          colors.backgroundHex,
          colors.detailHex
        ])
    }
}

@matinzd
Copy link
Member

matinzd commented Oct 26, 2019

Hiya,
is it possible to extent this lib to also extract colors of locale images?

Cheers,
Toni

Work in progress

@matinzd matinzd added enhancement New feature or request good first issue Good for newcomers labels Oct 26, 2019
@matinzd matinzd self-assigned this Oct 26, 2019
@matinzd
Copy link
Member

matinzd commented Oct 26, 2019

I'm a total noob in swift so it took me a while to get a version working on iOS with asset-library:// URL
Maybe this code can help to make a fast implemention?
Not doing a PR because the lack of Android support

//
//  DominantColor.swift
//  RNDominant Color
//
//  Created by Matin ZD on 7/11/1398 AP.
//  Copyright © 1398 Facebook. All rights reserved.
//

import Foundation
import UIKit
import Photos // use the Photos Framework

@objc(RNDominantColor)
class RNDominantColor : NSObject {
  
    @objc static func requiresMainQueueSetup() -> Bool {
        return false
    }
    
    @objc func getColorFromURI(_ imageURI: String,callback successCallback: @escaping RCTResponseSenderBlock ) {
        let url = URL(string: imageURI as String)
        
        let fetchResult = PHAsset.fetchAssets(withALAssetURLs: [url!], options: nil)
        if let phAsset = fetchResult.firstObject {
            PHImageManager.default().requestImageData(for: phAsset, options: nil) {
                (imageData, dataURI, orientation, info) -> Void in
                if let imageDataExists = imageData {
                    guard let colors = UIImage(data: imageDataExists)?.getColors() else {
                      return successCallback(["#00000000", "#00000000", "#00000000", "#00000000", "#00000000"])
                    }
                    successCallback([
                      colors.primaryHex,
                      colors.secondaryHex,
                      colors.backgroundHex,
                      colors.detailHex
                    ])
                }
            }
        } else {
          return successCallback(["#00000000", "#00000000", "#00000000", "#00000000", "#00000000"])
        }
    }

    @objc func getColorFromURL(_ imageURL: NSString,callback successCallback: RCTResponseSenderBlock ) {
        let url = URL(string: imageURL as String)
        let data = try? Data(contentsOf: url!)
        guard let colors = UIImage(data: data!)?.getColors() else {
          return successCallback(["#00000000", "#00000000", "#00000000", "#00000000", "#00000000"])
        }
        successCallback([
          colors.primaryHex,
          colors.secondaryHex,
          colors.backgroundHex,
          colors.detailHex
        ])
    }
}

Make Pull request please and we will workaround android :) Thanks!

I'm a total noob in swift so it took me a while to get a version working on iOS with asset-library:// URL
Maybe this code can help to make a fast implemention?
Not doing a PR because the lack of Android support

//
//  DominantColor.swift
//  RNDominant Color
//
//  Created by Matin ZD on 7/11/1398 AP.
//  Copyright © 1398 Facebook. All rights reserved.
//

import Foundation
import UIKit
import Photos // use the Photos Framework

@objc(RNDominantColor)
class RNDominantColor : NSObject {
  
    @objc static func requiresMainQueueSetup() -> Bool {
        return false
    }
    
    @objc func getColorFromURI(_ imageURI: String,callback successCallback: @escaping RCTResponseSenderBlock ) {
        let url = URL(string: imageURI as String)
        
        let fetchResult = PHAsset.fetchAssets(withALAssetURLs: [url!], options: nil)
        if let phAsset = fetchResult.firstObject {
            PHImageManager.default().requestImageData(for: phAsset, options: nil) {
                (imageData, dataURI, orientation, info) -> Void in
                if let imageDataExists = imageData {
                    guard let colors = UIImage(data: imageDataExists)?.getColors() else {
                      return successCallback(["#00000000", "#00000000", "#00000000", "#00000000", "#00000000"])
                    }
                    successCallback([
                      colors.primaryHex,
                      colors.secondaryHex,
                      colors.backgroundHex,
                      colors.detailHex
                    ])
                }
            }
        } else {
          return successCallback(["#00000000", "#00000000", "#00000000", "#00000000", "#00000000"])
        }
    }

    @objc func getColorFromURL(_ imageURL: NSString,callback successCallback: RCTResponseSenderBlock ) {
        let url = URL(string: imageURL as String)
        let data = try? Data(contentsOf: url!)
        guard let colors = UIImage(data: data!)?.getColors() else {
          return successCallback(["#00000000", "#00000000", "#00000000", "#00000000", "#00000000"])
        }
        successCallback([
          colors.primaryHex,
          colors.secondaryHex,
          colors.backgroundHex,
          colors.detailHex
        ])
    }
}

Make Pull request please and we will workaround android :) Thanks!

@Psiiirus
Copy link
Author

Hi @matinzd ,
I currently haven't any setup to create a proper PR but I have this .patch file with maybe can help?

rn-dominant-color+1.4.3.patch.zip

Do you have any articles about setting up a RN Project to do PRs for external libraries?

@matinzd
Copy link
Member

matinzd commented Oct 28, 2019 via email

@ithustle
Copy link

ithustle commented May 5, 2020

Anything about getting color from local images?

@farshed
Copy link

farshed commented May 9, 2020

+1

@geroale
Copy link

geroale commented May 27, 2020

Hello, any news?

@ShivamJoker
Copy link

I am also waiting please give some update

@matinzd
Copy link
Member

matinzd commented Aug 6, 2020

Working on issue in new branch. When it was stable we are going to publish thanks to @Psiiirus

@ithustle
Copy link

ithustle commented Oct 5, 2020

Anything?

@MadeByRaymond
Copy link

Hello, please any update on the yet?

@ShivamJoker
Copy link

2 years gone and still, guess it's abandoned

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers work in progress
Projects
None yet
Development

No branches or pull requests

7 participants