不确定我错过了什么。
尝试从简单输入[type = file] POST获取jpg并将其擦除为两个版本(1800x1800)和(400x400)。
代码:
stream.Position = 0;//probably only need one of these lines
stream.Seek(0, SeekOrigin.Begin);//i've tried both to no avail
ImageJob job = new ImageJob(stream, origStream,
new Instructions("maxwidth=1800&maxheight=1800")).Build();
抛出:
File may be corrupted, empty,
or may contain a PNG image with a single dimension greater than 65,535 pixels.
stream
来自context.Request.InputStream
我只是通过方法调用传递它。另一个是MemoryStream origStream = new MemoryStream()
using
我已经阅读了一些文档和一些引用此错误的其他SO帖子。我使用插件在SO引用上找到的所有内容,我都没有使用插件。
我最好的猜测是我缺少一些配置来让ImageResizer工作,但我还没有找到它。
PS如果我跳过图像处理步骤,我可以保存文件,因此图像流很好,我只是无法使用ImageResizer来更改它。
答案 0 :(得分:1)
问题出在输入流中。
frames= [] #holds gif images
weatherIND = 0 #frame of gif currently being displayed
#processes and initializes gif, then starts the loop
def getWeather()
global frames
frames= []
self.processImage("assets/Rain.gif")
print("frames len = " + str(len(frames)))
Photo = frames[0] #initialize
self.iconLbl.config(image=Photo)
self.iconLbl.image = Photo
self.after(0, self.update) #start the loop
#displays the next frame of the gif every 20 ms
def update(self):
global weatherInd
global frames
if weatherInd == (len(frames)):
weatherInd = 0
Photo = frames[weatherInd]
self.iconLbl.config(image=Photo)
self.iconLbl.image = Photo
weatherInd+=1
self.after(20, self.update)
#takes a gif and puts each frame in a list as a PhotoImage object
def processImage(self, path):
'''
Iterate the GIF, extracting each frame.
'''
global frames
mode = 'global'
im = Image.open(path)
i = 0
p = im.getpalette()
last_frame = im.convert('RGBA')
try:
while True:
print "saving %s (%s) frame %d, %s %s" % (path, mode, i, im.size, im.tile)
'''
If the GIF uses local colour tables, each frame will have its own palette.
If not, we need to apply the global palette to the new frame.
'''
if not im.getpalette():
im.putpalette(p)
new_frame = Image.new('RGBA', im.size)
'''
Is this file a "partial"-mode GIF where frames update a region of a different size to the entire image?
If so, we need to construct the new frame by pasting it on top of the preceding frames.
'''
if mode == 'partial':
new_frame.paste(last_frame)
new_frame.paste(im, (0,0), im.convert('RGBA'))
new_frame = new_frame.resize((100,100), Image.ANTIALIAS)
Photo = ImageTk.PhotoImage(new_frame)
frames.append(Photo)
i += 1
last_frame = new_frame
im.seek(im.tell() + 1)
except EOFError:
pass
应该是:
context.Request.InputStream
context.Request.Files[0].InputStream
悬挂在InputStream
上,包含整个身体,形式和所有内容。不是有效的图像。