Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Find Resolution of JPEG Image

def jpeg_res(filename):
   """"This function prints the resolution of the jpeg image file passed into it"""

   # open image for reading in binary mode
   with open(filename,'rb') as img_file:

       # height of image (in 2 bytes) is at 164th position
       img_file.seek(163)

       # read the 2 bytes
       a = img_file.read(2)

       # calculate height
       height = (a[0] << 8) + a[1]

       # next 2 bytes is width
       a = img_file.read(2)

       # calculate width
       width = (a[0] << 8) + a[1]

   print("The resolution of the image is",width,"x",height)

jpeg_res("img1.jpg")
Comment

PREVIOUS NEXT
Code Example
Python :: Matrix Transpose using Nested List Comprehension 
Python :: Source Code: Check Armstrong number of n digits 
Python :: jax.numpy 
Python :: pyqt5 different resolutions 
Python :: python get screen dpi 
Python :: django queryset or operator 
Python :: non venomous snakes 
Python :: how a 16 mp camera looks like 
Python :: how to delete lists after using them in python 
Python :: heads or tails python 
Python :: in np array how to make element as 1 if it exceeds the threshold 
Python :: python + credit-german.csv + class 
Python :: The module in NAME could not be imported: django.contrib.user_auth.password_validation.UserAttributeSimilarityValidator. Check your AUTH_PASSWORD_VALI 
Python :: import external script in django views 
Python :: find location of a class in python 
Python :: set shortcut for Qaction pyqt5 
Python :: main() invalid syntax 
Python :: add 10 min to current time django 
Python :: Implement a function word_list() that reads the 5_letter_words.txt file and returns a list of the words in the file. 
Python :: python einops rearrange 
Python :: defining a class in python 
Python :: can we use for loop inside if statement 
Python :: region python 
Python :: Complete the function that accepts a string parameter, and reverses each word in the string. All spaces in the string should be retained. 
Python :: poisson random data 
Python :: added variable plot python 
Python :: python project structure 
Python :: python SynC 
Python :: Understand the most appropriate graph to use for your dataset 
Python :: scaling, cross validation and fitting a model through a pipline 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =