コード例 #1
0
ファイル: models.py プロジェクト: edwinwow/pinimatic
 def save(self, *args, **kwargs):
     hash_name = os.urandom(32).encode('hex')
     #create image
     if not self.image:
         print 'model - if not self.image'
         temp_img = NamedTemporaryFile()
         if self.uImage:
             print 'model - self.uImage'
             image = Image.open(settings.TMP_ROOT+self.uImage)
         if self.imgUrl:
             print 'model - self.image'
             temp_img.write(urllib2.urlopen(self.imgUrl).read())
             temp_img.flush()
             image = Image.open(temp_img.name)
         if image.mode != "RGB":
             print 'model - image.mode'
             image = image.convert("RGB")
         image.save(temp_img.name, 'JPEG')
         self.image.save(''.join([hash_name, '.jpg']), File(temp_img))
         #create image thumbnail
         print 'model - starting thumbnail'
         super(Pin, self).save()
         temp_thumb = NamedTemporaryFile()
         size = image.size
         prop = 200.0 / float(image.size[0])
         size = (int(prop*float(image.size[0])), int(prop*float(image.size[1])))
         image.thumbnail(size, Image.ANTIALIAS)
         image.save(temp_thumb.name, 'JPEG')
         self.thumbnail.save(''.join([hash_name, '.jpg']), File(temp_thumb))
         print 'model - delete_uplaod called'
         if self.uImage:
             delete_upload(None, self.uImage)
         print 'model - thumbnail complete'
     
     if not self.srcUrl:
         print 'if not srcUrl'
         print self.image.name
         print self.image.url
         print self.srcUrl
         self.srcUrl = settings.MEDIA_URL+self.image.name
     #TODO: srcUrl gets http://domain but imgUrl does not?
     self.imgUrl = settings.MEDIA_URL+self.image.name
         
     super(Pin, self).save(*args, **kwargs)
コード例 #2
0
ファイル: models.py プロジェクト: arctelix/pinimatic
 def save(self, *args, **kwargs):
     hash_name = os.urandom(32).encode('hex')
     #create image
     if not self.image:
         print 'model - if not self.image'
         temp_img = NamedTemporaryFile()
         if self.uImage:
             print 'model - self.uImage'
             image = Image.open(settings.TMP_ROOT + self.uImage)
             self.imgName = self.uImage
         if self.imgUrl:
             print 'model - self.image'
             temp_img.write(urllib2.urlopen(self.imgUrl).read())
             temp_img.flush()
             image = Image.open(temp_img.name)
             self.imgName = self.imgUrl
         if image.mode != "RGB":
             print 'model - image.mode'
             image = image.convert("RGB")
         image.save(temp_img.name, 'JPEG')
         self.image.save(''.join([hash_name, '.jpg']), File(temp_img))
         #create image thumbnail
         print 'model - starting thumbnail'
         temp_thumb = NamedTemporaryFile()
         size = image.size
         prop = 200.0 / float(image.size[0])
         size = (int(prop * float(image.size[0])),
                 int(prop * float(image.size[1])))
         image.thumbnail(size, Image.ANTIALIAS)
         image.save(temp_thumb.name, 'JPEG')
         self.thumbnail.save(''.join([hash_name, '.jpg']), File(temp_thumb))
         #super(Pin, self).save()
         if self.uImage:
             print 'model - delete_uplaod called'
             delete_upload(None, self.uImage)
     media_url = settings.MEDIA_URL
     if not self.srcUrl:
         print 'model - if not srcUrl'
         self.srcUrl = media_url + self.image.name
     #always link to our saved image to prevent linking back to dead images.
     self.imgUrl = media_url + self.image.name
     super(Pin, self).save(*args, **kwargs)
コード例 #3
0
ファイル: models.py プロジェクト: Krispy2009/pinimatic
 def save(self, *args, **kwargs):
     hash_name = os.urandom(32).encode('hex')
     #create image
     if not self.image:
         print 'model - if not self.image'
         temp_img = NamedTemporaryFile()
         if self.uImage:
             print 'model - self.uImage'
             image = Image.open(settings.TMP_ROOT+self.uImage)
             self.imgName = self.uImage
         if self.imgUrl:
             print 'model - self.image'
             temp_img.write(urllib2.urlopen(self.imgUrl).read())
             temp_img.flush()
             image = Image.open(temp_img.name)
             self.imgName = self.imgUrl
         if image.mode != "RGB":
             print 'model - image.mode'
             image = image.convert("RGB")
         image.save(temp_img.name, 'JPEG')
         self.image.save(''.join([hash_name, '.jpg']), File(temp_img))
         #create image thumbnail
         print 'model - starting thumbnail'
         temp_thumb = NamedTemporaryFile()
         size = image.size
         prop = 200.0 / float(image.size[0])
         size = (int(prop*float(image.size[0])), int(prop*float(image.size[1])))
         image.thumbnail(size, Image.ANTIALIAS)
         image.save(temp_thumb.name, 'JPEG')
         self.thumbnail.save(''.join([hash_name, '.jpg']), File(temp_thumb))
         #super(Pin, self).save()
         if self.uImage:
             print 'model - delete_uplaod called'
             delete_upload(None, self.uImage)
     media_url = settings.MEDIA_URL
     if not self.srcUrl:
         print 'model - if not srcUrl'
         self.srcUrl = media_url+self.image.name
     #always link to our saved image to prevent linking back to dead images.
     self.imgUrl = media_url+self.image.name
     super(Pin, self).save(*args, **kwargs)