Permalink
Browse files

Use string generated from Time.now to set filename

  • Loading branch information...
1 parent 502aeae commit f1297a9f8cf5f0e0edf0a633ba480dbbb73fd3a3 @satococoa committed Feb 9, 2013
Showing with 4 additions and 2 deletions.
  1. +4 −2 app/friend.rb
View
6 app/friend.rb
@@ -42,12 +42,14 @@ def thumbnail
def self.save_with_image(image)
Dispatch::Queue.concurrent.async {
- image_path = UIImagePNGRepresentation(image).MD5HexDigest + '.png'
+ # 同じ写真を選択したとき、ファイル名がかぶるのを防ぐ
+ str = Time.now.to_i.to_s.dataUsingEncoding(NSUTF8StringEncoding).MD5HexDigest[0, 5]
+ image_path = str + UIImagePNGRepresentation(image).MD5HexDigest + '.png'
path = NSString.pathWithComponents([App.documents_path, image_path])
image.saveToPath(path, type:NYXImageTypePNG, backgroundFillColor:nil)
thumbnail = image.scaleToFitSize([256, 256])
- thumbnail_path = UIImagePNGRepresentation(thumbnail).MD5HexDigest + '.png'
+ thumbnail_path = str + UIImagePNGRepresentation(thumbnail).MD5HexDigest + '.png'
path = NSString.pathWithComponents([App.documents_path, thumbnail_path])
thumbnail.saveToPath(path, type:NYXImageTypePNG, backgroundFillColor:nil)

0 comments on commit f1297a9

Please sign in to comment.