I want to create and modify image of website, and image can be created in right location now as below code, but I can’t modify and format those images.
class Bookmark(models.Model):
title = models.CharField(max_length=200)
user = models.ForeignKey(User)
link = models.ForeignKey(Link)
def __unicode__(self):
return "%s, %s" % (self.user, self.link.url)
def save_image(self):
import subprocess
import os
url = self.link.url.replace("http://","").replace("https://","")\
.replace("/","|")
image_png = './teststatic/url_image/' + url + ".png"
image_jpg = './teststatic/url_image/' + url + ".jpg"
command_line = "python", "webkit2png.py","-o", image_png, self.link.url
image_crop = "mogrify", "-crop", "1280x1024+0+0", image_png
image_convert = "mogrify", "-format", "jpg", image_png
image_del = "rm", image_png
image_resize = "mogrify", "-resize", "150", "-quality", "80", image_jpg
p1=subprocess.Popen(command_line, stdout=subprocess.PIPE)
p2=subprocess.Popen(image_crop, stdin=p1.stdout, stdout=subprocess.PIPE)
p3=subprocess.Popen(image_convert, stdin=p2.stdout, stdout=subprocess.PIPE)
p4=subprocess.Popen(image_del, stdin=p3.stdout, stdout=subprocess.PIPE)
subprocess.Popen(image_resize, stdin=p4.stdout, stdout=subprocess.PIPE)
Here the error trace (reformated for readability) :
mogrify: unable to open image `./teststatic/url_image/z.cn.png': \
png.la @ error/blob.c/OpenBlob/2489mogrify: unable to open image \
`./teststatic/url_image/z.cn.png': png.la @ error/blob.c/OpenBlob/2489rm: \
cannot remove `./teststatic/url_image/z.cn.png': No such file or directory
.
mogrify: unable to open image `./teststatic/url_image/z.cn.png': \
@ error/blob.c/OpenBlob/2489.
mogrify: unable to open file `./teststatic/url_image/z.cn.png' \
@ error/png.c/ReadPNGImage/2951.
.
mogrify: unable to open image `./teststatic/url_image/z.cn.png': \
@ error/blob.c/OpenBlob/2489.
mogrify: unable to open file `./teststatic/url_image/z.cn.png' \
@ error/png.c/ReadPNGImage/2951.
mogrify: unable to open image `./teststatic/url_image/z.cn.jpg': \
jpeg.la @ error/blob.c/OpenBlob/2489.
mogrify: unable to open image `./teststatic/url_image/z.cn.jpg': \
@ error/blob.c/OpenBlob/2489.
rm: cannot remove `./teststatic/url_image/www.igoogle.com|.png': \
No such file or directory
mogrify: unable to open image `./teststatic/url_image/www.igoogle.com|.png': \
png.la @ error/blob.c/OpenBlob/2489.
mogrify: unable to open image `./teststatic/url_image/www.igoogle.com|.png': \
@ error/blob.c/OpenBlob/2489.
mogrify: unable to open file `./teststatic/url_image/www.igoogle.com|.png'\
@ error/png.c/ReadPNGImage/2951.
mogrify: unable to open image `./teststatic/url_image/www.igoogle.com|.png':\
png.la @ error/blob.c/OpenBlob/2489mogrify: unable to open image \
`./teststatic/url_image/www.igoogle.com|.jpg': \
jpeg.la @ error/blob.c/OpenBlob/2489.
mogrify: unable to open image `./teststatic/url_image/www.igoogle.com|.png': \
@ error/blob.c/OpenBlob/2489.
mogrify: unable to open file `./teststatic/url_image/www.igoogle.com|.png' \
@ error/png.c/ReadPNGImage/2951.
rm: .
mogrify: unable to open image `./teststatic/url_image/www.igoogle.com|.jpg': \
@ error/blob.c/OpenBlob/2489.
cannot remove `./teststatic/url_image/www.z.cn|.png': No such file or directory
mogrify: unable to open image `./teststatic/url_image/www.z.cn|.png':\
png.la @ error/blob.c/OpenBlob/2489.
mogrify: unable to open image `./teststatic/url_image/www.z.cn|.png': \
@ error/blob.c/OpenBlob/2489.
mogrify: unable to open file `./teststatic/url_image/www.z.cn|.png'\
@ error/png.c/ReadPNGImage/2951.
mogrify: unable to open image `./teststatic/url_image/www.z.cn|.png': \
png.la @ error/blob.c/OpenBlob/2489.
mogrify: unable to open image `./teststatic/url_image/www.z.cn|.png': \
@ error/blob.c/OpenBlob/2489.
mogrify: unable to open file `./teststatic/url_image/www.z.cn|.png'\
@ error/png.c/ReadPNGImage/2951.
rm: mogrify: unable to open image `./teststatic/url_image/www.z.cn|.jpg': \
jpeg.la @ error/blob.c/OpenBlob/2489cannot remove `./teststatic/url_image
...
...
The pipe has some problems, how do I solve this?
Your second process depends on the file which is generated by the first process. However the first process is not yet finished when the second is started, so
pngimage does not yet exists. Usesubprocess.call()instead, or thewait()method: