public function removeTransformsForAsset(Asset $asset)
    {
        $config = self::getConfig();

        try {
            $sourceModel = new LocalSourceImageModel($asset);
            $targetModel = new LocalTargetImageModel($sourceModel, []);

            if (strpos($targetModel->path, $config->imagerSystemPath) !== false) {
                try {
                    FileHelper::clearDirectory(FileHelper::normalizePath($targetModel->path));
                } catch (ErrorException $e) {
                    Craft::error('Could not clear directory "'.$targetModel->path.'" ('.$e->getMessage().')', __METHOD__);
                } catch (InvalidParamException $e) {
                    Craft::error('Could not clear directory "'.$targetModel->path.'" ('.$e->getMessage().')', __METHOD__);
                }

                Craft::$app->templateCaches->deleteCachesByElementId($asset->id);

                if ($sourceModel->type !== 'local' && file_exists($sourceModel->getFilePath())) {
                    try {
                        FileHelper::unlink($sourceModel->getFilePath());
                    } catch (ErrorException $e) {
                        Craft::error('Could not remove file "'.$sourceModel->getFilePath().'" ('.$e->getMessage().')', __METHOD__);
                    }
                }
            }
        } catch (ImagerException $e) {
            Craft::error($e->getMessage(), __METHOD__);
        }
    }
public function removeTransformsForAsset(Asset $asset)
    {
        $config = self::getConfig();

        try {
            $sourceModel = new LocalSourceImageModel($asset);
            $targetModel = new LocalTargetImageModel($sourceModel, []);

            if (strpos($targetModel->path, $config->imagerSystemPath) !== false) {
                try {
                    FileHelper::clearDirectory(FileHelper::normalizePath($targetModel->path));
                } catch (ErrorException $e) {
                    Craft::error('Could not clear directory "'.$targetModel->path.'" ('.$e->getMessage().')', __METHOD__);
                } catch (InvalidParamException $e) {
                    Craft::error('Could not clear directory "'.$targetModel->path.'" ('.$e->getMessage().')', __METHOD__);
                }

                Craft::$app->templateCaches->deleteCachesByElementId($asset->id);

                if ($sourceModel->type !== 'local' && file_exists($sourceModel->getFilePath())) {
                    try {
                        FileHelper::unlink($sourceModel->getFilePath());
                    } catch (ErrorException $e) {
                        Craft::error('Could not remove file "'.$sourceModel->getFilePath().'" ('.$e->getMessage().')', __METHOD__);
                    }
                }
            }
        } catch (ImagerException $e) {
            Craft::error($e->getMessage(), __METHOD__);
        }
    }
public function removeTransformsForAsset ( Asset $ asset ) { $ config = self :: getConfig ( ) ; try { $ sourceModel = new LocalSourceImageModel ( $ asset ) ; $ targetModel = new LocalTargetImageModel ( $ sourceModel , [ ] ) ; if ( strpos ( $ targetModel -> path , $ config -> imagerSystemPath ) !== false ) { try { FileHelper :: clearDirectory ( FileHelper :: normalizePath ( $ targetModel -> path ) ) ; } catch ( ErrorException $ e ) { Craft :: error ( 'Could not clear directory "' . $ targetModel -> path . '" (' . $ e -> getMessage ( ) . ')' , __METHOD__ ) ; } catch ( InvalidParamException $ e ) { Craft :: error ( 'Could not clear directory "' . $ targetModel -> path . '" (' . $ e -> getMessage ( ) . ')' , __METHOD__ ) ; } Craft :: $ app -> templateCaches -> deleteCachesByElementId ( $ asset -> id ) ; if ( $ sourceModel -> type !== 'local' && file_exists ( $ sourceModel -> getFilePath ( ) ) ) { try { FileHelper :: unlink ( $ sourceModel -> getFilePath ( ) ) ; } catch ( ErrorException $ e ) { Craft :: error ( 'Could not remove file "' . $ sourceModel -> getFilePath ( ) . '" (' . $ e -> getMessage ( ) . ')' , __METHOD__ ) ; } } } } catch ( ImagerException $ e ) { Craft :: error ( $ e -> getMessage ( ) , __METHOD__ ) ; } }
Remove transforms for a given asset

@param Asset $asset
Remove transforms for a given asset