public function getDimensions($dim = "string") {
        if(!$this->getField('Filename')) {
            return null;
        }

        $imageDimensions = $this->getDimensionsFromDB($dim);
        if ($imageDimensions !== null) {
            return $imageDimensions;
        }

        // Download file from S3/CDN if we do not have dimensions stored in the DB
        $pointer = $this->obj('CDNFile');
        if($this->ID && $pointer->exists()) {
            $this->ensureLocalFile();
        }

        if (!$this->localFileExists()) {
            return null;
        }

        // Store in 'ImageDim' field and write if they've changed.
        $this->storeDimensions();
        if ($this->isChanged('ImageDim', \DataObject::CHANGE_VALUE)) {
            $this->write();
        }
        // Load dimensions
        return $this->getDimensionsFromDB($dim);
    }