prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  ImageView only works with square images
  I created a hello world app following this tutorial under Linux Mint 20: [https://docs.beeware.org/en/latest/tutorial/tutorial-0.html](https://docs.beeware.org/en/latest/tutorial/tutorial-0.html)
  My python version is 3.8.5
  When trying to add images some work and some not.
  
  This code doesn't work:
  `image_from_url = toga.Image("https://dummyimage.com/100x67/000/fff")
  imageview_from_url = toga.ImageView(image=image_from_url, style=Pack(width=100, height=67))`
  
  And this is working fine:
  `image_from_url = toga.Image("https://dummyimage.com/100x100/000/fff")
  imageview_from_url = toga.ImageView(image=image_from_url, style=Pack(width=100, height=100))`
  
  The error I get is:
  
  > (__main__.py:67130): GdkPixbuf-CRITICAL **: 16:12:00.644: gdk_pixbuf_scale_simple: assertion 'dest_height > 0' failed
  >  ... TypeError: Argument 0 does not allow None as a value
  
  
  </issue>
  <code>
  [start of src/gtk/toga_gtk/widgets/imageview.py]
  1 from ..libs import GdkPixbuf, Gtk, Gdk
  2 from .base import Widget
  3 
  4 
  5 class ImageView(Widget):
  6     def create(self):
  7         self.native = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
  8         self._image = Gtk.Image()
  9         self._pixbuf = None
  10         self.native.add(self._image)
  11         self.native.interface = self.interface
  12 
  13     def set_image(self, image):
  14         self._pixbuf = image._impl.native
  15 
  16     def set_bounds(self, x, y, width, height):
  17         super().set_bounds(x, y, width, height)
  18         # rehint to update scaling of pixbuf
  19         self.rehint()
  20 
  21     def rehint(self):
  22         if self._pixbuf:
  23             height, width = self._resize_max(
  24                 original_height=self._pixbuf.get_height(),
  25                 original_width=self._pixbuf.get_width(),
  26                 max_height=self.native.get_allocated_height(),
  27                 max_width=self.native.get_allocated_width(),
  28             )
  29 
  30             dpr = self.native.get_scale_factor()
  31 
  32             scaled_pixbuf = self._pixbuf.scale_simple(
  33                 width * dpr, height * dpr, GdkPixbuf.InterpType.BILINEAR
  34             )
  35 
  36             surface = Gdk.cairo_surface_create_from_pixbuf(
  37                 scaled_pixbuf, 0, self.native.get_window()  # scale: 0 = same as window
  38             )
  39             self._image.set_from_surface(surface)
  40 
  41     @staticmethod
  42     def _resize_max(original_height, original_width, max_height, max_width):
  43 
  44         # Check to make sure all dimensions have valid sizes
  45         if min(original_height, original_width, max_height, max_width) <= 0:
  46             return 1, 1
  47 
  48         width_ratio = max_width / original_width
  49         height_ratio = max_height / original_height
  50 
  51         height = original_height * width_ratio
  52         if height <= max_height:
  53             width = original_width * width_ratio
  54         else:
  55             height = original_height * height_ratio
  56             width = original_width * height_ratio
  57 
  58         return int(height), int(width)
  59
  [end of src/gtk/toga_gtk/widgets/imageview.py]
  [start of examples/imageview/imageview/app.py]
  1 import toga
  2 from toga.style.pack import CENTER, COLUMN
  3 
  4 
  5 class ImageViewApp(toga.App):
  6     def startup(self):
  7         self.main_window = toga.MainWindow(title=self.name)
  8 
  9         box = toga.Box()
  10         box.style.padding = 40
  11         box.style.update(alignment=CENTER)
  12         box.style.update(direction=COLUMN)
  13 
  14         # image from local path
  15         # load brutus.png from the package
  16         # We set the style width/height parameters for this one
  17         image_from_path = toga.Image('resources/brutus.png')
  18         imageview_from_path = toga.ImageView(image_from_path)
  19         imageview_from_path.style.update(height=72)
  20         imageview_from_path.style.update(width=72)
  21         box.add(imageview_from_path)
  22 
  23         # image from remote URL
  24         # no style parameters - we let Pack determine how to allocate
  25         # the space
  26         image_from_url = toga.Image('https://beeware.org/project/projects/libraries/toga/toga.png')
  27         imageview_from_url = toga.ImageView(image_from_url)
  28         box.add(imageview_from_url)
  29 
  30         self.main_window.content = box
  31         self.main_window.show()
  32 
  33 
  34 def main():
  35     return ImageViewApp('ImageView', 'org.beeware.widgets.imageview')
  36 
  37 
  38 if __name__ == '__main__':
  39     app = main()
  40     app.main_loop()
  41
  [end of examples/imageview/imageview/app.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/examples/imageview/imageview/app.py b/examples/imageview/imageview/app.py
  --- a/examples/imageview/imageview/app.py
  +++ b/examples/imageview/imageview/app.py
  @@ -14,10 +14,9 @@
           # image from local path
           # load brutus.png from the package
           # We set the style width/height parameters for this one
  -        image_from_path = toga.Image('resources/brutus.png')
  +        image_from_path = toga.Image('resources/pride-brutus.png')
           imageview_from_path = toga.ImageView(image_from_path)
           imageview_from_path.style.update(height=72)
  -        imageview_from_path.style.update(width=72)
           box.add(imageview_from_path)
   
           # image from remote URL
  diff --git a/src/gtk/toga_gtk/widgets/imageview.py b/src/gtk/toga_gtk/widgets/imageview.py
  --- a/src/gtk/toga_gtk/widgets/imageview.py
  +++ b/src/gtk/toga_gtk/widgets/imageview.py
  @@ -55,4 +55,8 @@
               height = original_height * height_ratio
               width = original_width * height_ratio
   
  -        return int(height), int(width)
  +        # On the first display the allocated height/width will be 1x1.
  +        # If the image isn't square, this will result in one of the dimensions
  +        # scaling to 0, which breaks GTK. So; constraint the minimum height
  +        # and width to 1.
  +        return max(int(height), 1), max(int(width), 1)
  
verification_info: {"golden_diff": "diff --git a/examples/imageview/imageview/app.py b/examples/imageview/imageview/app.py\n--- a/examples/imageview/imageview/app.py\n+++ b/examples/imageview/imageview/app.py\n@@ -14,10 +14,9 @@\n         # image from local path\n         # load brutus.png from the package\n         # We set the style width/height parameters for this one\n-        image_from_path = toga.Image('resources/brutus.png')\n+        image_from_path = toga.Image('resources/pride-brutus.png')\n         imageview_from_path = toga.ImageView(image_from_path)\n         imageview_from_path.style.update(height=72)\n-        imageview_from_path.style.update(width=72)\n         box.add(imageview_from_path)\n \n         # image from remote URL\ndiff --git a/src/gtk/toga_gtk/widgets/imageview.py b/src/gtk/toga_gtk/widgets/imageview.py\n--- a/src/gtk/toga_gtk/widgets/imageview.py\n+++ b/src/gtk/toga_gtk/widgets/imageview.py\n@@ -55,4 +55,8 @@\n             height = original_height * height_ratio\n             width = original_width * height_ratio\n \n-        return int(height), int(width)\n+        # On the first display the allocated height/width will be 1x1.\n+        # If the image isn't square, this will result in one of the dimensions\n+        # scaling to 0, which breaks GTK. So; constraint the minimum height\n+        # and width to 1.\n+        return max(int(height), 1), max(int(width), 1)\n", "issue": "ImageView only works with square images\nI created a hello world app following this tutorial under Linux Mint 20: [https://docs.beeware.org/en/latest/tutorial/tutorial-0.html](https://docs.beeware.org/en/latest/tutorial/tutorial-0.html)\r\nMy python version is 3.8.5\r\nWhen trying to add images some work and some not.\r\n\r\nThis code doesn't work:\r\n`image_from_url = toga.Image(\"https://dummyimage.com/100x67/000/fff\")\r\nimageview_from_url = toga.ImageView(image=image_from_url, style=Pack(width=100, height=67))`\r\n\r\nAnd this is working fine:\r\n`image_from_url = toga.Image(\"https://dummyimage.com/100x100/000/fff\")\r\nimageview_from_url = toga.ImageView(image=image_from_url, style=Pack(width=100, height=100))`\r\n\r\nThe error I get is:\r\n\r\n> (__main__.py:67130): GdkPixbuf-CRITICAL **: 16:12:00.644: gdk_pixbuf_scale_simple: assertion 'dest_height > 0' failed\r\n>  ... TypeError: Argument 0 does not allow None as a value\r\n\n", "before_files": [{"content": "from ..libs import GdkPixbuf, Gtk, Gdk\nfrom .base import Widget\n\n\nclass ImageView(Widget):\n    def create(self):\n        self.native = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)\n        self._image = Gtk.Image()\n        self._pixbuf = None\n        self.native.add(self._image)\n        self.native.interface = self.interface\n\n    def set_image(self, image):\n        self._pixbuf = image._impl.native\n\n    def set_bounds(self, x, y, width, height):\n        super().set_bounds(x, y, width, height)\n        # rehint to update scaling of pixbuf\n        self.rehint()\n\n    def rehint(self):\n        if self._pixbuf:\n            height, width = self._resize_max(\n                original_height=self._pixbuf.get_height(),\n                original_width=self._pixbuf.get_width(),\n                max_height=self.native.get_allocated_height(),\n                max_width=self.native.get_allocated_width(),\n            )\n\n            dpr = self.native.get_scale_factor()\n\n            scaled_pixbuf = self._pixbuf.scale_simple(\n                width * dpr, height * dpr, GdkPixbuf.InterpType.BILINEAR\n            )\n\n            surface = Gdk.cairo_surface_create_from_pixbuf(\n                scaled_pixbuf, 0, self.native.get_window()  # scale: 0 = same as window\n            )\n            self._image.set_from_surface(surface)\n\n    @staticmethod\n    def _resize_max(original_height, original_width, max_height, max_width):\n\n        # Check to make sure all dimensions have valid sizes\n        if min(original_height, original_width, max_height, max_width) <= 0:\n            return 1, 1\n\n        width_ratio = max_width / original_width\n        height_ratio = max_height / original_height\n\n        height = original_height * width_ratio\n        if height <= max_height:\n            width = original_width * width_ratio\n        else:\n            height = original_height * height_ratio\n            width = original_width * height_ratio\n\n        return int(height), int(width)\n", "path": "src/gtk/toga_gtk/widgets/imageview.py"}, {"content": "import toga\nfrom toga.style.pack import CENTER, COLUMN\n\n\nclass ImageViewApp(toga.App):\n    def startup(self):\n        self.main_window = toga.MainWindow(title=self.name)\n\n        box = toga.Box()\n        box.style.padding = 40\n        box.style.update(alignment=CENTER)\n        box.style.update(direction=COLUMN)\n\n        # image from local path\n        # load brutus.png from the package\n        # We set the style width/height parameters for this one\n        image_from_path = toga.Image('resources/brutus.png')\n        imageview_from_path = toga.ImageView(image_from_path)\n        imageview_from_path.style.update(height=72)\n        imageview_from_path.style.update(width=72)\n        box.add(imageview_from_path)\n\n        # image from remote URL\n        # no style parameters - we let Pack determine how to allocate\n        # the space\n        image_from_url = toga.Image('https://beeware.org/project/projects/libraries/toga/toga.png')\n        imageview_from_url = toga.ImageView(image_from_url)\n        box.add(imageview_from_url)\n\n        self.main_window.content = box\n        self.main_window.show()\n\n\ndef main():\n    return ImageViewApp('ImageView', 'org.beeware.widgets.imageview')\n\n\nif __name__ == '__main__':\n    app = main()\n    app.main_loop()\n", "path": "examples/imageview/imageview/app.py"}]}