ImageManager.php
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace common\components;
use artbox\core\components\imagemanager\components\ImageManagerGetPath;
/**
 * Class ImageManager
 * @package common\components
 */
class ImageManager extends ImageManagerGetPath
{
    /**
     * @inheritdoc
     */
    public function getImagePath($ImageManager_id, $width = 400, $height = 400, $thumbnailMode = "outbound")
    {
        //default return
        $return = null;
        $mImageManager = ImageManager::findOne($ImageManager_id);
        //check if not empty
        if ($mImageManager !== null) {
            //set crop mode
            $mode = $thumbnailMode == "outbound" ? "outbound" : "inset";
            $sMediaPath = null;
            if ($this->mediaPath !== null) {
                $sMediaPath = $this->mediaPath;
            }
            $sFileExtension = pathinfo($mImageManager->fileName, PATHINFO_EXTENSION);
            //get image file path
            $sImageFilePath = $sMediaPath . '/' . $mImageManager->id . '_' . $mImageManager->fileHash . '.' . $sFileExtension;
            //check file exists
            if (file_exists($sImageFilePath)) {
                $return = \Yii::$app->imageresize->getUrl(
                    $sImageFilePath,
                    $width,
                    $height,
                    $mode,
                    100,
                    $mImageManager->fileName
                );
            } else {
                $return = null; //isset(\Yii::$app->controller->module->assetPublishedUrl) ? \Yii::$app->controller->module->assetPublishedUrl. "/img/img_no-image.png" : null;
            }
        }
        return $return;
    }
}