﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
11158	get_image_dimensions very slow after 1 call	kua	SAn	"get_image_dimensions in django.core.files.images is very slow after 1 call

This has the effect of slowing down calls to save on model image fields, the whole thing shudders to a halt while we spin around in PIL.Image.feed

The issue is that the read pointer is not being reset after the call to get_image_dimensions. Subsequent calls to file.read

To reproduce:


from django.core.files.images import get_image_dimensions[[BR]]
from django.core.files.uploadedfile import File[[BR]]

f = File(open('/tmp/some_multi_megabyte_file.jpg')[[BR]]
get_image_dimensions(f)[[BR]]
get_image_dimensions(f)[[BR]]



I suggest this function should save the read pointer pos, reset it to 0, then do all the PIL fancyness, then reset the pointer when finished. I've tried to attach a patch that reflects this

Imagine this scenario: Someone mucks with the read pointer on a hundred meg image, say reads 2 kilobytes. Then this function is called and starts reading data in 1K chunks looking for a header (which has already been skipped). 

So 100 Megabytes - 2 kilobytes / 1024 bytes per read means this function will be called over 100,000 times
"		closed	Core (Other)	dev		fixed	get_image_dimensions, field, save, slow		Ready for checkin	1	0	0	0	0	0
