public function createImage($fileId, $filterId)
    {
        $image = StorageImage::find()->where(['file_id' => $fileId, 'filter_id' => $filterId])->one();

        // the image exists already in the database and the file system
        if ($image && $image->fileExists) {
            return $image;
        }

        $file = StorageFile::findOne($fileId);

        if (!$file) {
            return false;
        }
        // create the new image name
        $fileName = $filterId.'_'.$file->name_new_compound;

        $fromTempFile = tempnam(sys_get_temp_dir(), 'fromFile');
        $fromTempFile.= $fileName;

        $content = $file->getContent();

        // it seems the content can not be found.
        if ($content === false) {
            return false;
        }

        $writeFile = FileHelper::writeFile($fromTempFile, $content);

        // unable to write the temp file
        if (!$writeFile) {
            return false;
        }

        // create a temp file
        $tempFile = tempnam(sys_get_temp_dir(), 'destFile');
        $tempFile.= $fileName;

        // there is no filter, which means we create an image version for a given file.
        if (empty($filterId)) {
            @copy($fromTempFile, $tempFile);
        } else {
            $filter = StorageFilter::findOne($filterId);
            if (!$filter || !$filter->applyFilterChain($fromTempFile, $tempFile)) {
                return false;
            }
        }

        $resolution = Storage::getImageResolution($tempFile);
        // now copy the file to the storage system
        $this->fileSystemSaveFile($tempFile, $fileName);
        unlink($tempFile);
        unlink($fromTempFile);

        $this->flushImageArray();

        // ensure the existing of the model
        if ($image) {
            $image->resolution_height = $resolution['height'];
            $image->resolution_width = $resolution['width'];
            $image->save();

            return $image;
        }

        $image = new StorageImage();
        $image->file_id = $fileId;
        $image->filter_id = $filterId;
        $image->resolution_height = $resolution['height'];
        $image->resolution_width = $resolution['width'];
        if (!$image->save()) {
            return false;
        }

        return $image;
    }