Permalink
Browse files

Merge pull request #26 from satococoa/22-fix-duplicate-filename

ファイル名がかぶらないように修正しました
  • Loading branch information...
2 parents 4ced26d + f1297a9 commit 9bef128b0f51f23b80f9723e0669b21c1f660312 @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 9bef128

Please sign in to comment.