本文整理汇总了PHP中N2Filesystem::absoluteURLToPath方法的典型用法代码示例。如果您正苦于以下问题:PHP N2Filesystem::absoluteURLToPath方法的具体用法?PHP N2Filesystem::absoluteURLToPath怎么用?PHP N2Filesystem::absoluteURLToPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类N2Filesystem
的用法示例。
在下文中一共展示了N2Filesystem::absoluteURLToPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scaleImage
public static function scaleImage($group, $imageUrl, $scale = 1, $resizeRemote = false)
{
$originalImageUrl = $imageUrl;
$imageUrl = N2ImageHelper::fixed($imageUrl);
if ($scale > 0 && function_exists('exif_imagetype') && function_exists('imagecreatefrompng')) {
if (substr($imageUrl, 0, 2) == '//') {
$imageUrl = parse_url(N2Uri::getBaseuri(), PHP_URL_SCHEME) . ':' . $imageUrl;
}
$imageUrl = N2Uri::relativetoabsolute($imageUrl);
$imagePath = N2Filesystem::absoluteURLToPath($imageUrl);
$cache = new self($group);
if ($imagePath == $imageUrl) {
// The image is not local
if (!$resizeRemote) {
return $originalImageUrl;
}
$pathInfo = pathinfo(parse_url($imageUrl, PHP_URL_PATH));
$extension = self::validateExtension($pathInfo['extension']);
if (!$extension) {
return $originalImageUrl;
}
return N2ImageHelper::dynamic(N2Filesystem::pathToAbsoluteURL($cache->makeCache($extension, array($cache, '_scaleRemoteImage'), array($extension, $imageUrl, $scale))));
} else {
$extension = false;
$imageType = @exif_imagetype($imagePath);
switch ($imageType) {
case IMAGETYPE_JPEG:
$extension = 'jpg';
break;
case IMAGETYPE_PNG:
$extension = 'png';
$fp = fopen($imagePath, 'r');
fseek($fp, 25);
$data = fgets($fp, 2);
fclose($fp);
if (ord($data) == 3) {
// GD cannot resize palette PNG so we return the original image
return $originalImageUrl;
}
break;
}
if (!$extension) {
throw new Exception('Filtype of the image is not supported: #' . $imageType . ' code ' . $imagePath);
}
return N2ImageHelper::dynamic(N2Filesystem::pathToAbsoluteURL($cache->makeCache($extension, array($cache, '_scaleImage'), array($extension, $imagePath, $scale, filemtime($imagePath)))));
}
}
}
示例2: replaceHTMLImage
public function replaceHTMLImage($found)
{
$path = N2Filesystem::absoluteURLToPath(self::addProtocol($found[2]));
if ($path == $found[2]) {
return $found[0];
}
if (N2Filesystem::fileexists($path)) {
if (!isset($this->imageTranslation[$path])) {
$fileName = strtolower(basename($path));
while (in_array($fileName, $this->usedNames)) {
$fileName = $this->uniqueCounter . $fileName;
$this->uniqueCounter++;
}
$this->usedNames[] = $fileName;
$this->files['images/' . $fileName] = file_get_contents($path);
$this->imageTranslation[$path] = $fileName;
} else {
$fileName = $this->imageTranslation[$path];
}
return str_replace($found[2], 'images/' . $fileName, $found[0]);
} else {
return $found[0];
}
}