@staticmethod<EOL><INDENT>def calculate_dimensions(image_size, desired_size):<DEDENT>
current_x, current_y = image_size<EOL>target_x, target_y = desired_size<EOL>if current_x < target_x and current_y < target_y:<EOL><INDENT>return None<EOL><DEDENT>if current_x > target_x:<EOL><INDENT>new_x0 = floor(current_x / <NUM_LIT:2>)<EOL>new_x = new_x0 - ceil(target_x / <NUM_LIT:2>)<EOL>new_width = target_x<EOL><DEDENT>else:<EOL><INDENT>new_x = <NUM_LIT:0><EOL>new_width = current_x<EOL><DEDENT>if current_y > target_y:<EOL><INDENT>new_y0 = floor(current_y / <NUM_LIT:2>)<EOL>new_y = new_y0 - ceil(target_y / <NUM_LIT:2>)<EOL>new_height = target_y<EOL><DEDENT>else:<EOL><INDENT>new_y = <NUM_LIT:0><EOL>new_height = current_y<EOL><DEDENT>return (int(new_x), int(new_y), new_width, new_height)<EOL>
Return the Tuple with the arguments to pass to Image.crop.

        If the image is smaller than than the desired_size Don't do
        anything. Otherwise, first calculate the (truncated) center and then
        take half the width and height (truncated again) for x and y.

        x0, y0: the center coordinates