Get the size of a locally loaded large image

I am trying to read the width and height of a locally loaded image. This seems to work for images that do not exceed the sizes limited by Flash Player 10 ( http://kb2.adobe.com/cps/496/cpsid_49662.html ), but as soon as the images are larger, the width and height remain 0. Strange the thing is that from time to time I can read the dimension of these large images, but most of the time not. I understand that this may be due to a player’s limitation, but then I would at least expect the error to be consistent.

I want to check this because there is no use uploading such a large image, since it will not be displayed in any case, but it would be useful to provide a detailed error message to the user.

Any ideas on this?

Here is the code I use to upload the image locally and read the measurement:

private function chooseImageButton_clickHandler(event:Event):void { var allowedTypes:String = "*.jpg;*.png"; m_uploadFileReference = new FileReference(); m_uploadFileReference.addEventListener(Event.SELECT, uploadFileReference_selectHandler); m_uploadFileReference.addEventListener(Event.COMPLETE, uploadFileReference_completeHandler); m_uploadFileReference.browse([new FileFilter("Image Files (" + allowedTypes + ")", allowedTypes)]); } private function uploadFileReference_selectHandler(event:Event):void { m_uploadFileReference.load(); } private function uploadFileReference_completeHandler(event:Event):void { var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded); loader.loadBytes(m_uploadFileReference.data); } private function onImageLoaded(e:Event):void { trace(e.target.content.width); } 
+2
source share
2 answers

You can skip downloading the entire image and just read the headers using this class .

 var je : JPGSizeExtractor = new JPGSizeExtractor( ); je.addEventListener( JPGSizeExtractor.PARSE_COMPLETE, sizeHandler ); je.extractSize( your_jpg_file.jpg ); function sizeHandler( e : Event ) : void {  trace( "Dimensions: " + je.width + " x " + je.height ); } 

Be faster and more reliable.

+4
source

I would at least expect the error to be consistent.

Well, at least Adobe says quite clearly about this: "... if you decide to go beyond that, we cannot guarantee consistent behavior."

Could you upload your image to the php preprocessor? ( Here from google)

0
source

Source: https://habr.com/ru/post/1492224/


All Articles