Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

how can i optimize the compress process? #4

Open
edison0951 opened this issue Dec 10, 2018 · 0 comments
Open

how can i optimize the compress process? #4

edison0951 opened this issue Dec 10, 2018 · 0 comments

Comments

@edison0951
Copy link

edison0951 commented Dec 10, 2018

Now I use the tinify-ruby script to compress our images. And I process 160 images that need almost nine minutes. This is my code:

@@index = 0

@@api_keys = []

def self.tinify(file_path)

    if @@api_keys.length == 0

      UI.message("no api keys found")

      return

    end

    Tinify.key = @@api_keys[@@index]

    UI.message("current api key is: #{Tinify.key}")

    file_name = File.basename file_path

    UI.message("#{file_name} start to ready compress image")

    begin

      source = Tinify.from_file file_path

      source.to_file file_path

      UI.message("#{file_name} compress success!")

      @@index += 1

      if @@index == @@api_keys.length

        @@index = 0

      end

    rescue Tinify::AccountError => e

      @@index += 1

      if @@index == @@api_keys.length

        @@index = 0

      end

      tinify file_path

    rescue => e

      UI.message("#{file_name} compress failure!")

      @@index += 1

      if @@index == @@api_keys.length

        @@index = 0

      end

    end

 end

how can I optimize the process time?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant