<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(self, path, im):
 """ Generate assets from the given image and path in case you've already called Image.open """

        # Get the original filename
        _, filename = os.path.split(path)

        # Generate the new filename
        filename = self.get_safe_filename(filename)
        filename = '%s%s' % (self.prefix if self.prefix else '', filename)

        # Get the original image size
        w, h = im.size

        # Generate assets from the source image
        for d in DENSITY_TYPES:
            if d == 'ldpi' and not self.ldpi:
                continue  # skip ldpi
            if d == 'xxxhdpi' and not self.xxxhdpi:
                continue  # skip xxxhdpi

            out_file = os.path.join(self.out,
                    self.get_out_for_density(d), filename)

            if d == self.source_density:
                im.save(out_file, quality=self.image_quality)
            else:
                size = (self.get_size_for_density(w, d),
                        self.get_size_for_density(h, d))
                im.resize(size, self.image_filter).save(out_file,
                        quality=self.image_quality)