title: PyGame - Getting the size of a loaded image
body: <p><strong>Hello, even though you might think there was a similar question, mine is pretty different than <a href="https://stackoverflow.com/questions/16840711/how-to-get-the-picture-size-in-pygame-python">this</a>.</strong></p>
  
  <p>I am trying to load an image from a directory, and set my screen size (automatically) to the size of the image being loaded as "background".</p>
  
  <pre><code>import pygame
  import sys
  from pygame.locals import *
  
  image_resources = "C:/Users/user/Desktop/Pygame App/image_resources/"
  
  class load:
      def image(self, image):
          self.image = image
          return (image_resources + image)
      def texture(self, texture):
          self.texture = texture
          return (image_resources + texture)
  
  bg = load().image("bg_solid_black.jpg")
  
  pygame.init()
  
  #screen = pygame.display.set_mode((width,height),0,32)
  
  #background = pygame.image.load(bg).convert()
  
  #width = background.get_width()
  #height = background.get_height()
  </code></pre>
  
  <p>The image that I loaded with my "load()" class is set to the variable "bg" and I want to use the size of whatever I load as "bg" to determine the size of the window. If you try to move</p>
  
  <pre><code>background = pygame.image.load(bg).convert()
  
  width = background.get_width()
  height = background.get_height()
  </code></pre>
  
  <p>On top of this:</p>
  
  <pre><code>screen = pygame.display.set_mode((width,height),0,32)
  </code></pre>
  
  <p>PyGame returns an error, in which it states that the display mode is not set. If I do it like this:</p>
  
  <pre><code>screen = pygame.display.set_mode((width,height),0,32)
  
  background = pygame.image.load(bg).convert()
  
  width = background.get_width()
  height = background.get_height()
  </code></pre>
  
  <p>of course, this is not true, since variables "width" and "height" are not defined for the use of "pygame.display.set_mode()". </p>
  
  <p>I can not seem to figure this out, I though of solving through an OO manner, but I just can not seem to figure it out. Any help?</p>
  
  <p>Thanks :)</p>