public function onAfterLoadIntoFile($file)
    {
        // return if not an image
        if (!$file->getIsImage()) {
            return;
        }

        // get parent folder path
        $folder = rtrim($file->Parent()->getFilename(), '/');

        $custom_folders = $this->config()->get('custom_folders');

        if (!empty($custom_folders[$folder]) && is_array($custom_folders[$folder])) {
            foreach ($custom_folders[$folder] as $key => $val) {
                $this->config()->set($key, $val);
            }
        }

        if ($this->config()->get('bypass')) {
            return;
        }

        $this->config_max_width = $this->config()->get('max_width');
        $this->config_max_height = $this->config()->get('max_height');
        $this->config_auto_rotate = $this->config()->get('auto_rotate');
        $this->config_force_resampling = $this->config()->get('force_resampling');

        $extension = $file->getExtension();

        if ($this->config_force_resampling ||
            ($this->config_max_height && $file->getHeight() > $this->config_max_height) ||
            ($this->config_max_width && $file->getWidth() > $this->config_max_width) ||
            ($this->config_auto_rotate && preg_match('/jpe?g/i', $file->getExtension()))
        ) {
            $this->scaleUploadedImage($file);
        }
    }