I have a model, I would like create a thumbnail by ImageMagick( yes with line command ), it works , but I cant associate the image created with the field “mini” in my model MedicoImage.
class MedicoImage(models.Model):
medico = models.ForeignKey(Medico)
imagem = models.ImageField(max_length=300,upload_to='img_medico')
mini = models.ImageField(max_length=300,upload_to='img_medico/mini',verbose_name=u'Miniatura',null=True, blank=True)
def save(self, *args, **kwargs):
super(MedicoImage, self).save(*args, **kwargs)
if not self.mini:
path_destino = os.path.dirname(self.imagem.path) + '/mini/'
path_destino += os.path.basename(self.imagem.path).partition('.')[0] + '_mini' + '.png'
comando = 'convert ' + self.imagem.path + ' -resize 30% ' + path_destino
if subprocess.call(comando,shell=True) == 0:
f = File(open(path_destino,'r'))
self.mini(path_destino, f.read())
self.mini.save()
print 'Thumbnail created!'
What is wrong here?
f = File(open(path_destino,'r'))
self.mini(path_destino, f.read())
self.mini.save()
Just use:
I think that should do it.