def target_size_center_crop(self, im, new_hw):
        """
        Crop and resize the image to the target size while keeping the center.
        """
        width, height = im.size
        if width != height:
            im = self.crop(im, min(height, width), min(height, width))
        return im.resize((new_hw, new_hw), PIL.Image.LANCZOS)

        Crop and resize the image to the target size while keeping the center.
        
src/diffusers/pipelines/stable_diffusion_gligen/pipeline_stable_diffusion_gligen_text_image.py