<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _resize(image, width, height, crop):
 """ Resize the image with respect to the aspect ratio """

    ext = os.path.splitext(image.name)[1].strip(".")

    with Image(file=image, format=ext) as b_image:
        # Account for orientation
        if ORIENTATION_TYPES.index(b_image.orientation) > 4:
            # Flip
            target_aspect = float(width) / float(height)
            aspect = float(b_image.height) / float(b_image.width)
        else:
            target_aspect = float(width) / float(height)
            aspect = float(b_image.width) / float(b_image.height)

        # Fix rotation
        b_image.auto_orient()

        # Calculate target size
        target_aspect = float(width) / float(height)
        aspect = float(b_image.width) / float(b_image.height)

        if ((target_aspect > aspect and not crop) or
                (target_aspect <= aspect and crop)):
            # target is wider than image, set height as maximum
            target_height = height

            # calculate width
            # -  iw / ih = tw / th (keep aspect)
            # => th ( iw / ih ) = tw
            target_width = float(target_height) * aspect

            if crop:
                # calculate crop coords
                # -  ( tw - w ) / 2
                target_left = (float(target_width) - float(width)) / 2
                target_left = int(round(target_left))
                target_top = 0

            # correct floating point error, and convert to int, round in the
            # direction of the requested width
            if width >= target_width:
                target_width = int(math.ceil(target_width))
            else:
                target_width = int(math.floor(target_width))
        else:
            # image is wider than target, set width as maximum
            target_width = width

            # calculate height
            # -  iw / ih = tw / th (keep aspect)
            # => tw / ( iw / ih ) = th
            target_height = float(target_width) / aspect

            if crop:
                # calculate crop coords
                # -  ( th - h ) / 2
                target_top = (float(target_height) - float(height)) / 2
                target_top = int(round(target_top))
                target_left = 0

            # correct floating point error and convert to int
            if height >= target_height:
                target_height = int(math.ceil(target_height))
            else:
                target_height = int(math.floor(target_height))

        # strip color profiles
        b_image.strip()

        # Resize
        b_image.resize(target_width, target_height)

        if crop:
            # Crop to target
            b_image.crop(left=target_left, top=target_top, width=width,
                         height=height)

        # Save to temporary file
        temp_file = tempfile.TemporaryFile()
        b_image.save(file=temp_file)
        # Rewind the file
        temp_file.seek(0)
        return temp_file