Формирование ссылки на загруженное изображение с проверкой наличия на диске

@param null $size

@return mixed|null|string
331433
function getUrl($size = null) {
        $url = $this->makeUrl($size);
        //на случай получения картинок с другого сервера
        $prefix = (string) env('LARAKIT_THUMB_PREFIX');
        if(!$prefix) {
            //если со своего - проверяем их наличие
            $file = public_path($url);
            if(file_exists($file)) {
                return $url;
                //                return $url . '?' . microtime(true);
            }
        }
        else {
            return $url;
            //            return $url . '?' . microtime(true);
        }
        
        return $size ? $this->getSize($size)
                            ->getDefault() : null;
    }
384315
public function size($size = null)
    {
        /* To do: function should be called ratio() */
        if (is_null($size)) {
            if (isset($this->size_attribute)) {
                return $this->size_attribute;
            } else {
                return;
            }
        }
        $size = $this->parseSize($size)->raw;
        $this->size_attribute = $size;
        $this->todo('resize');

        return $this;
    }
449180
public function setSize($size)
    {
        $this->cachedParams = null;

        $this->checkSize($size);

        $this->size = $size;

        return $this;
    }
625441
public function setPageSize($size)
    {
        $this->pageSize = ($size === null ? self::PAGE_SIZE : (int)$size);
        if ($this->pageSize < 0)
            $this->pageSize = self::PAGE_SIZE;

        return $this;
    }
340306
public function getCoverFile($size)
    {
        $coverFilename = $this->coverFilename;

        //get the extension
        $extension = explode('.', $coverFilename);
        $extension = array_pop($extension);

        //remove file extension
        $name = preg_replace('#\.[^.]*$#', '', $coverFilename);
        $coverFilename = $name.'_'.$size.'.'.$extension;

        return $coverFilename;
    }
118168
public static function getImageSize( string $size = 'thumbnail') {
		$sizes = self::getImageSizes();
		$size  = key_exists( $size, $sizes ) ? $size : 'thumbnail';

		return $sizes[ $size ];
	}
114207
public function getMaxColumns($size = null)
    {
        if (is_object($this->content) && property_exists($this->content, 'maxColumns') && !is_null($this->content->maxColumns)) {
            return $this->content->maxColumns;
        }
        if (is_null($size)) {
            $size = $this->baseSize;
        }
        $columnAttribute = 'max' . ucfirst($size) . 'Columns';

        return $this->{$columnAttribute};
    }
13352
public function setSize($size)
    {
        if (null === $size) {
            return $this;
        }

        $this->size = $size;
        $this->pixelRatio = (int) round($size / 5);

        return $this;
    }
505184
public function getPixelValue(string $size)
    {
        $value = preg_replace('/[^0-9.-]+/', '', $size);
        $unit = preg_replace('/[^acehimnprtvwx%]/', '', $size);

        // Convert 16px = 1em = 2ex = 12pt = 1pc = 1/6in = 2.54/6cm = 25.4/6mm = 100%
        switch ($unit) {
            case '':
            case 'px':
                return (int) round($value);

                break;

            case 'em':
                return (int) round($value * 16);

                break;

            case 'ex':
                return (int) round($value * 16 / 2);

                break;

            case 'pt':
                return (int) round($value * 16 / 12);

                break;

            case 'pc':
                return (int) round($value * 16);

                break;

            case 'in':
                return (int) round($value * 16 * 6);

                break;

            case 'cm':
                return (int) round($value * 16 / (2.54 / 6));

                break;

            case 'mm':
                return (int) round($value * 16 / (25.4 / 6));

                break;

            case '%':
                return (int) round($value * 16 / 100);

                break;
        }

        return 0;
    }
1042470
public function getBatch($size = 10)
    {
        return $this->getConnection()->transactional(function () use ($size) {
            $emails = $this->find()
                ->where([
                    $this->aliasField('sent') => false,
                    $this->aliasField('send_tries') . ' <=' => 3,
                    $this->aliasField('send_at') . ' <=' => new FrozenTime('now'),
                    $this->aliasField('locked') => false,
                ])
                ->limit($size)
                ->order([$this->aliasField('created') => 'ASC']);

            $emails
                ->extract('id')
                ->through(function (\Cake\Collection\CollectionInterface $ids) {
                    if (!$ids->isEmpty()) {
                        $this->updateAll(['locked' => true], ['id IN' => $ids->toList()]);
                    }

                    return $ids;
                });

            return $emails->toList();
        });
    }
1334618
public function generate($size)
    {
        $result = '';
        for ($i = 0; $i < $size; $i++) {
            $result .= chr((rand() ^ rand()) % 256);
        }

        return $result;
    }
830619
public function url($size)
    {

        return $this->img_server . '/' . $this->type . '/' . $this->id .
            '_' . $size . '.' . $this->extension;

    }
1301711
public static function ProfileImage(string $userName = NULL, int $size = 0)
    {
        $sizeSuffix = $size == 0 ? "" : "@{$size}";
        $s = static::$DataUrl . "/profimg/{$userName}{$sizeSuffix}";
        return $s;
    }
821438
private function migrateSize(?string $size): ?string
    {
        if ($size === null) {
            return null;
        }


        $columns = array_map(
            function (array $column) {
                if ($column['width'] === 'auto') {
                    $column['width'] = 'equal';
                }

                return $column;
            },
            StringUtil::deserialize($size, true)
        );

        return serialize($columns);
    }
1024342
protected function find_image_size_from_width( $sizes, $width ) {
		foreach ( $sizes as $name => $size ) {
			if ( $width === $size['width'] ) {
				return $name;
			}
		}
		return null;
	}
85396
public function setSize($size) {
		$this->owner->ButtonSize = trim(strtolower($size));
		return $this->owner;
	}
32183
public function size( $size ) {
		$this->width  = (int) $size;
		$this->height = (int) $size;

		return $this;
	}