def crop_corners(image, box=None, **kwargs):
    """
    Crop corners to the selection defined by image_cropping
    """

    if box:
        values = [int(x) for x in box.split(',')]
        box = (
            int(values[0]),
            int(values[1]),
            int(values[2]),
            int(values[3]),
        )
        image = image.crop(box)

    return image


def crop_corners(image, box=None, **kwargs):
    """
    Crop corners to the selection defined by image_cropping
    """

    if box:
        values = [int(x) for x in box.split(',')]
        width = abs(values[2] - values[0])
        height = abs(values[3] - values[1])
        if width != image.size[0] or height != image.size[1]:
            image = image.crop(*values)

    return image


Scale image only if necessary to avoid compression artefacts
Scale image only if necessary to avoid compression artefacts

  def crop_corners(image, box=None, **kwargs):
      """
      Crop corners to the selection defined by image_cropping
      """
  
      if box:
          values = [int(x) for x in box.split(',')]
+         width = abs(values[2] - values[0])
+         height = abs(values[3] - values[1])
+         if width != image.size[0] or height != image.size[1]:
-         box = (
-             int(values[0]),
-             int(values[1]),
-             int(values[2]),
-             int(values[3]),
-         )
-         image = image.crop(box)
+             image = image.crop(*values)
  
      return image
  
  
Scale image only if necessary to avoid compression artefacts
## Code Before:
def crop_corners(image, box=None, **kwargs):
    """
    Crop corners to the selection defined by image_cropping
    """

    if box:
        values = [int(x) for x in box.split(',')]
        box = (
            int(values[0]),
            int(values[1]),
            int(values[2]),
            int(values[3]),
        )
        image = image.crop(box)

    return image


## Instruction:
Scale image only if necessary to avoid compression artefacts
## Code After:
def crop_corners(image, box=None, **kwargs):
    """
    Crop corners to the selection defined by image_cropping
    """

    if box:
        values = [int(x) for x in box.split(',')]
        width = abs(values[2] - values[0])
        height = abs(values[3] - values[1])
        if width != image.size[0] or height != image.size[1]:
            image = image.crop(*values)

    return image

