Commits

mgron  committed 5bf4dac

+) get png image proportions

  • Participants
  • Parent commits f6a11d6

Comments (0)

Files changed (1)

File src/samplomat/ImageMeasure.as

 			var stream : FileStream = new FileStream();
 				stream.open(file, FileMode.READ);
 				
-			if(stream.bytesAvailable >= 10)
+			if( stream.readUnsignedByte() == 0x47 && 
+				stream.readUnsignedByte() == 0x49 &&
+				stream.readUnsignedByte() == 0x46)
 			{
-				if( stream.readUnsignedByte() == 0x47 && 
-					stream.readUnsignedByte() == 0x49 &&
-					stream.readUnsignedByte() == 0x46)
-				{
-					stream.position += 3;
-					height = stream.readUnsignedByte() | (stream.readUnsignedByte() << 8);
-					width = stream.readUnsignedByte() | (stream.readUnsignedByte() << 8);
-					dimensions = new Rectangle(0, 0, width, height);
-				}
+				stream.position += 3;
+				height = stream.readUnsignedByte() | (stream.readUnsignedByte() << 8);
+				width = stream.readUnsignedByte() | (stream.readUnsignedByte() << 8);
+				dimensions = new Rectangle(0, 0, width, height);
 			}
 			
 			return dimensions;
 		
 		public function png(file : File) : Rectangle
 		{
-			return null;
+			var dimensions : Rectangle;
+			var width : Number, height : Number;
+			var stream : FileStream = new FileStream();
+				stream.open(file, FileMode.READ);
+			
+			if(	stream.readUnsignedByte() == 0x89 &&
+				stream.readUnsignedByte() == 0x50 &&
+				stream.readUnsignedByte() == 0x4e)
+			{
+				stream.position += 15;
+				width = stream.readUnsignedByte() << 8 | (stream.readUnsignedByte());
+				stream.position += 2;
+				height = stream.readUnsignedByte() << 8 | (stream.readUnsignedByte());
+				dimensions = new Rectangle(0, 0, width, height);
+			}
+				
+			return dimensions;
 		}
 		
 		public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void