Пример #1
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
$arResult["ELEMENT"]["URL"]["~DOWNLOAD"] = $arResult["ELEMENT"]["URL"]["DOWNLOAD"];
if (!isset($arParams["THUMB_SIZE"]) && isset($_REQUEST["size"])) {
    $arParams["THUMB_SIZE"] = $_REQUEST["size"] > 0 && $_REQUEST["size"] < 600 ? $_REQUEST["size"] : 600;
}
if (isset($arParams["THUMB_SIZE"])) {
    if (CFile::IsImage($arResult["ELEMENT"]['NAME'], $arResult["ELEMENT"]['FILE']["CONTENT_TYPE"])) {
        CFile::ScaleImage($arResult["ELEMENT"]["FILE"]["WIDTH"], $arResult["ELEMENT"]["FILE"]["HEIGHT"], array("width" => $arParams["THUMB_SIZE"], "height" => $arParams["THUMB_SIZE"]), BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
        if ($bNeedCreatePicture) {
            $arResult["ELEMENT"]["original"] = array("src" => $arResult["ELEMENT"]["URL"]["DOWNLOAD"], "width" => $arResult["ELEMENT"]["FILE"]["WIDTH"], "height" => $arResult["ELEMENT"]["FILE"]["HEIGHT"]);
            $arResult["ELEMENT"]["FILE"]["WIDTH"] = $arDestinationSize["width"];
            $arResult["ELEMENT"]["FILE"]["HEIGHT"] = $arDestinationSize["height"];
            $arResult["ELEMENT"]["URL"]["DOWNLOAD"] = WDAddPageParams($arResult["ELEMENT"]["URL"]["DOWNLOAD"], array("cache_image" => "Y", "width" => $arParams["THUMB_SIZE"], "height" => $arParams["THUMB_SIZE"]));
        }
    }
}
Пример #2
0
 public static function ResizeImageFileDelay(&$arDestinationSize, $sourceFile, $destinationFile, $arResizeParams)
 {
     global $DB;
     $destinationFile = preg_replace("/^https?:/i", "", $destinationFile);
     $q = $DB->Query("\n\t\t\tselect\n\t\t\t\tID\n\t\t\t\t,ERROR_CODE\n\t\t\t\t,PARAMS\n\t\t\t\t," . $DB->DateToCharFunction("TIMESTAMP_X", "FULL") . " TIMESTAMP_X\n\t\t\tfrom b_clouds_file_resize\n\t\t\twhere TO_PATH = '" . $DB->ForSql($destinationFile) . "'\n\t\t");
     if ($resize = $q->Fetch()) {
         if ($resize["ERROR_CODE"] === "0") {
             $arResizeParams = unserialize($resize["PARAMS"]);
             $id = $resize["ID"];
         } elseif (MakeTimeStamp($resize["TIMESTAMP_X"]) + 300 < time() + CTimeZone::GetOffset()) {
             $DB->Query("\n\t\t\t\t\tUPDATE b_clouds_file_resize\n\t\t\t\t\tSET ERROR_CODE='0'\n\t\t\t\t\tWHERE ID=" . $resize["ID"] . "\n\t\t\t\t");
             $arResizeParams = unserialize($resize["PARAMS"]);
             $id = $resize["ID"];
         } else {
             return false;
         }
     } else {
         $id = 0;
     }
     $sourceImageWidth = $sourceFile["WIDTH"];
     $sourceImageHeight = $sourceFile["HEIGHT"];
     $arSize = $arResizeParams[0];
     $resizeType = $arResizeParams[1];
     $arWaterMark = $arResizeParams[2];
     $jpgQuality = $arResizeParams[3];
     $arFilters = $arResizeParams[4];
     $bNeedCreatePicture = false;
     $arSourceSize = array("x" => 0, "y" => 0, "width" => 0, "height" => 0);
     $arDestinationSize = array("x" => 0, "y" => 0, "width" => 0, "height" => 0);
     CFile::ScaleImage($sourceImageWidth, $sourceImageHeight, $arSize, $resizeType, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
     $bNeedCreatePicture |= is_array($arWaterMark) && !empty($arWaterMark);
     $bNeedCreatePicture |= is_array($arFilters) && !empty($arFilters);
     if ($bNeedCreatePicture) {
         if ($id <= 0) {
             $id = $DB->Add("b_clouds_file_resize", array("~TIMESTAMP_X" => $DB->CurrentTimeFunction(), "ERROR_CODE" => "0", "PARAMS" => serialize($arResizeParams), "FROM_PATH" => $sourceFile["SRC"], "TO_PATH" => $destinationFile, "FILE_ID" => $sourceFile["ID"]));
         }
         return $id > 0;
     } else {
         return false;
     }
 }
Пример #3
0
 function ResizeImageFile($sourceFile, &$destinationFile, $arSize, $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL, $arWaterMark = array(), $jpgQuality = false, $arFilters = false)
 {
     $io = CBXVirtualIo::GetInstance();
     if (!$io->FileExists($sourceFile)) {
         return false;
     }
     $bNeedCreatePicture = false;
     if ($resizeType != BX_RESIZE_IMAGE_EXACT && $resizeType != BX_RESIZE_IMAGE_PROPORTIONAL_ALT) {
         $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL;
     }
     if (!is_array($arSize)) {
         $arSize = array();
     }
     if (!array_key_exists("width", $arSize) || intval($arSize["width"]) <= 0) {
         $arSize["width"] = 0;
     }
     if (!array_key_exists("height", $arSize) || intval($arSize["height"]) <= 0) {
         $arSize["height"] = 0;
     }
     $arSize["width"] = intval($arSize["width"]);
     $arSize["height"] = intval($arSize["height"]);
     $arSourceSize = array("x" => 0, "y" => 0, "width" => 0, "height" => 0);
     $arDestinationSize = array("x" => 0, "y" => 0, "width" => 0, "height" => 0);
     $arSourceFileSizeTmp = CFile::GetImageSize($sourceFile);
     if (!in_array($arSourceFileSizeTmp[2], array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_BMP))) {
         return false;
     }
     if (class_exists("imagick") && function_exists('memory_get_usage')) {
         //When memory limit reached we'll try to use ImageMagic
         $memoryNeeded = round(($arSourceFileSizeTmp[0] * $arSourceFileSizeTmp[1] * $arSourceFileSizeTmp['bits'] * ($arSourceFileSizeTmp['channels'] > 0 ? $arSourceFileSizeTmp['channels'] : 1) / 8 + pow(2, 16)) * 1.65);
         $memoryLimit = CUtil::Unformat(ini_get('memory_limit'));
         if (memory_get_usage() + $memoryNeeded > $memoryLimit) {
             if ($arSize["width"] <= 0 || $arSize["height"] <= 0) {
                 $arSize["width"] = $arSourceFileSizeTmp[0];
                 $arSize["height"] = $arSourceFileSizeTmp[1];
             }
             CFile::ScaleImage($arSourceFileSizeTmp[0], $arSourceFileSizeTmp[1], $arSize, $resizeType, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
             if ($bNeedCreatePicture) {
                 $new_image = CTempFile::GetFileName(bx_basename($sourceFile));
                 CheckDirPath($new_image);
                 $im = new Imagick();
                 try {
                     $im->setSize($arDestinationSize["width"], $arDestinationSize["height"]);
                     $im->readImage($io->GetPhysicalName($sourceFile));
                     $im->setImageFileName($new_image);
                     $im->thumbnailImage($arDestinationSize["width"], $arDestinationSize["height"], true);
                     $im->writeImage();
                     $im->destroy();
                 } catch (ImagickException $e) {
                     $new_image = "";
                 }
                 if ($new_image != "") {
                     $sourceFile = $new_image;
                     $arSourceFileSizeTmp = CFile::GetImageSize($io->GetPhysicalName($sourceFile));
                 }
             }
         }
     }
     if ($io->Copy($sourceFile, $destinationFile)) {
         switch ($arSourceFileSizeTmp[2]) {
             case IMAGETYPE_GIF:
                 $sourceImage = imagecreatefromgif($io->GetPhysicalName($sourceFile));
                 $bHasAlpha = true;
                 break;
             case IMAGETYPE_PNG:
                 $sourceImage = imagecreatefrompng($io->GetPhysicalName($sourceFile));
                 $bHasAlpha = true;
                 break;
             case IMAGETYPE_BMP:
                 $sourceImage = CFile::ImageCreateFromBMP($io->GetPhysicalName($sourceFile));
                 $bHasAlpha = false;
                 break;
             default:
                 $sourceImage = imagecreatefromjpeg($io->GetPhysicalName($sourceFile));
                 $bHasAlpha = false;
                 break;
         }
         $sourceImageWidth = intval(imagesx($sourceImage));
         $sourceImageHeight = intval(imagesy($sourceImage));
         if ($sourceImageWidth > 0 && $sourceImageHeight > 0) {
             if ($arSize["width"] <= 0 || $arSize["height"] <= 0) {
                 $arSize["width"] = $sourceImageWidth;
                 $arSize["height"] = $sourceImageHeight;
             }
             CFile::ScaleImage($sourceImageWidth, $sourceImageHeight, $arSize, $resizeType, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
             if ($bNeedCreatePicture) {
                 if (CFile::IsGD2()) {
                     $picture = ImageCreateTrueColor($arDestinationSize["width"], $arDestinationSize["height"]);
                     if ($arSourceFileSizeTmp[2] == IMAGETYPE_PNG) {
                         $transparentcolor = imagecolorallocatealpha($picture, 0, 0, 0, 127);
                         imagefilledrectangle($picture, 0, 0, $arDestinationSize["width"], $arDestinationSize["height"], $transparentcolor);
                         imagealphablending($picture, false);
                         imagecopyresampled($picture, $sourceImage, 0, 0, $arSourceSize["x"], $arSourceSize["y"], $arDestinationSize["width"], $arDestinationSize["height"], $arSourceSize["width"], $arSourceSize["height"]);
                         imagealphablending($picture, true);
                     } elseif ($arSourceFileSizeTmp[2] == IMAGETYPE_GIF) {
                         imagepalettecopy($picture, $sourceImage);
                         //Save transparency for GIFs
                         $transparentcolor = imagecolortransparent($sourceImage);
                         if ($transparentcolor >= 0 && $transparentcolor < imagecolorstotal($sourceImage)) {
                             $RGB = imagecolorsforindex($sourceImage, $transparentcolor);
                             $transparentcolor = imagecolorallocate($picture, $RGB["red"], $RGB["green"], $RGB["blue"]);
                             imagecolortransparent($picture, $transparentcolor);
                             imagefilledrectangle($picture, 0, 0, $arDestinationSize["width"], $arDestinationSize["height"], $transparentcolor);
                         }
                         imagecopyresampled($picture, $sourceImage, 0, 0, $arSourceSize["x"], $arSourceSize["y"], $arDestinationSize["width"], $arDestinationSize["height"], $arSourceSize["width"], $arSourceSize["height"]);
                     } else {
                         imagecopyresampled($picture, $sourceImage, 0, 0, $arSourceSize["x"], $arSourceSize["y"], $arDestinationSize["width"], $arDestinationSize["height"], $arSourceSize["width"], $arSourceSize["height"]);
                     }
                 } else {
                     $picture = ImageCreate($arDestinationSize["width"], $arDestinationSize["height"]);
                     imagecopyresized($picture, $sourceImage, 0, 0, $arSourceSize["x"], $arSourceSize["y"], $arDestinationSize["width"], $arDestinationSize["height"], $arSourceSize["width"], $arSourceSize["height"]);
                 }
             } else {
                 $picture = $sourceImage;
             }
             if (is_array($arFilters)) {
                 foreach ($arFilters as $arFilter) {
                     $bNeedCreatePicture |= CFile::ApplyImageFilter($picture, $arFilter, $bHasAlpha);
                 }
             }
             if (is_array($arWaterMark)) {
                 $arWaterMark["name"] = "watermark";
                 $bNeedCreatePicture |= CFile::ApplyImageFilter($picture, $arWaterMark, $bHasAlpha);
             }
             if ($bNeedCreatePicture) {
                 if ($io->FileExists($destinationFile)) {
                     $io->Delete($destinationFile);
                 }
                 switch ($arSourceFileSizeTmp[2]) {
                     case IMAGETYPE_GIF:
                         imagegif($picture, $io->GetPhysicalName($destinationFile));
                         break;
                     case IMAGETYPE_PNG:
                         imagealphablending($picture, false);
                         imagesavealpha($picture, true);
                         imagepng($picture, $io->GetPhysicalName($destinationFile));
                         break;
                     default:
                         if ($arSourceFileSizeTmp[2] == IMAGETYPE_BMP) {
                             $destinationFile .= ".jpg";
                         }
                         if ($jpgQuality === false) {
                             $jpgQuality = intval(COption::GetOptionString('main', 'image_resize_quality', '95'));
                         }
                         if ($jpgQuality <= 0 || $jpgQuality > 100) {
                             $jpgQuality = 95;
                         }
                         imagejpeg($picture, $io->GetPhysicalName($destinationFile), $jpgQuality);
                         break;
                 }
                 imagedestroy($picture);
             }
         }
         return true;
     }
     return false;
 }
Пример #4
0
$arParams["FAMILY"] = trim($arParams["FAMILY"]);
$arParams["FAMILY"] = strtolower(empty($arParams["FAMILY"]) ? "forum" : $arParams["FAMILY"]);
$arParams["FAMILY"] = preg_replace("/[^a-z]/is", "", $arParams["FAMILY"]);
$arParams["RETURN"] = $arParams["RETURN"] == "Y" ? "Y" : "N";
$arParams["MODE"] = trim($arParams["MODE"]);
// *************************/ADDITIONAL ****************************************************************
// *************************/Input params***************************************************************
$img["~src"] = $arParams["URL"];
$img["src_download"] = $arParams["URL"] . (strpos($arParams["URL"], '?') !== false ? '&' : '?') . "action=download";
$img["src"] = $arParams["URL"] . (strpos($arParams["URL"], '?') !== false ? '&' : '?') . ($arParams["MAX_SIZE"] !== null ? http_build_query($arParams["MAX_SIZE"]) : "");
// HTML size
$bNeedCreatePicture = false;
$props = ($img["width"] > 0 ? 'width="' . $img["width"] . '" ' : '') . ($img["height"] > 0 ? 'height="' . $img["height"] . '" ' : '');
if ($arParams["HTML_SIZE"] !== null) {
    if ($arParams["HTML_SIZE"]["width"] > 0 && $arParams["HTML_SIZE"]["height"] > 0 && $img["width"] > 0 && $img["height"] > 0) {
        CFile::ScaleImage($img["width"], $img["height"], $arParams["HTML_SIZE"], BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
        if ($bNeedCreatePicture) {
            $props = 'width="' . $arDestinationSize["width"] . '" height="' . $arDestinationSize["height"] . '" ';
        }
    } else {
        $style = array();
        if ($arParams["HTML_SIZE"]["width"] > 0) {
            $style[] = 'max-width:' . $arParams["HTML_SIZE"]["width"] . 'px;';
        }
        if ($arParams["HTML_SIZE"]["height"] > 0) {
            $style[] = 'max-height:' . $arParams["HTML_SIZE"]["height"] . 'px;';
        }
        if (!empty($style)) {
            $props = 'style="' . implode($style, "") . '"';
        }
    }
Пример #5
0
<?php

require $_SERVER["DOCUMENT_ROOT"] . "/mobile/headers.php";
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/header.php";
$width = intval($_REQUEST["width"]);
$height = intval($_REQUEST["height"]);
$fid = intval($_REQUEST["fid"]);
$bfid = intval($_REQUEST["bfid"]);
if ($fid > 0) {
    $db_img_arr = CFile::GetFileArray($fid);
    if ($db_img_arr) {
        CFile::ScaleImage($db_img_arr["WIDTH"], $db_img_arr["HEIGHT"], array("width" => $width, "height" => $height), BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
        ?>
<img width="<?php 
        echo intval($arDestinationSize["width"] / 2);
        ?>
" height="<?php 
        echo intval($arDestinationSize["height"] / 2);
        ?>
" src="/bitrix/components/bitrix/blog/show_file.php?fid=<?php 
        echo $bfid;
        ?>
&width=<?php 
        echo $width;
        ?>
&height=<?php 
        echo $height;
        ?>
" alt="" title=""><?php 
    }
}
Пример #6
0
	function ResizeImageFile($sourceFile, &$destinationFile, $arSize, $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL, $arWaterMark = array(), $jpgQuality=false, $arFilters=false)
	{
		$io = CBXVirtualIo::GetInstance();

		$bNeedCreatePicture = false;

		if ($resizeType != BX_RESIZE_IMAGE_EXACT && $resizeType != BX_RESIZE_IMAGE_PROPORTIONAL_ALT)
			$resizeType = BX_RESIZE_IMAGE_PROPORTIONAL;

		if (!is_array($arSize))
			$arSize = array();
		if (!array_key_exists("width", $arSize) || intval($arSize["width"]) <= 0)
			$arSize["width"] = 0;
		if (!array_key_exists("height", $arSize) || intval($arSize["height"]) <= 0)
			$arSize["height"] = 0;
		$arSize["width"] = intval($arSize["width"]);
		$arSize["height"] = intval($arSize["height"]);

		$arSourceSize = array("x" => 0, "y" => 0, "width" => 0, "height" => 0);
		$arDestinationSize = array("x" => 0, "y" => 0, "width" => 0, "height" => 0);

		$arSourceFileSizeTmp = CFile::GetImageSize($sourceFile);
		if (!in_array($arSourceFileSizeTmp[2], array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_BMP)))
			return false;

		if (!$io->FileExists($sourceFile))
			return false;

		if ($io->Copy($sourceFile, $destinationFile))
		{
			switch ($arSourceFileSizeTmp[2])
			{
				case IMAGETYPE_GIF:
					$sourceImage = imagecreatefromgif($io->GetPhysicalName($sourceFile));
					$bHasAlpha = true;
					break;
				case IMAGETYPE_PNG:
					$sourceImage = imagecreatefrompng($io->GetPhysicalName($sourceFile));
					$bHasAlpha = true;
					break;
				case IMAGETYPE_BMP:
					$sourceImage = CFile::ImageCreateFromBMP($sourceFile);
					$bHasAlpha = false;
					break;
				default:
					$sourceImage = imagecreatefromjpeg($io->GetPhysicalName($sourceFile));
					$bHasAlpha = false;
					break;
			}

			$sourceImageWidth = intval(imagesx($sourceImage));
			$sourceImageHeight = intval(imagesy($sourceImage));

			if ($sourceImageWidth > 0 && $sourceImageHeight > 0)
			{
				if ($arSize["width"] <= 0 || $arSize["height"] <= 0)
				{
					$arSize["width"] = $sourceImageWidth;
					$arSize["height"] = $sourceImageHeight;
				}

				CFile::ScaleImage($sourceImageWidth, $sourceImageHeight, $arSize, $resizeType, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);

				if ($bNeedCreatePicture)
				{
					if (CFile::IsGD2())
					{
						$picture = ImageCreateTrueColor($arDestinationSize["width"], $arDestinationSize["height"]);
						if($arSourceFileSizeTmp[2] == IMAGETYPE_PNG)
						{
							$transparentcolor = imagecolorallocatealpha($picture, 0, 0, 0, 127);
							imagefilledrectangle($picture, 0, 0, $arDestinationSize["width"], $arDestinationSize["height"], $transparentcolor);

							imagealphablending($picture, false);
							imagecopyresampled($picture, $sourceImage,
								0, 0, $arSourceSize["x"], $arSourceSize["y"],
								$arDestinationSize["width"], $arDestinationSize["height"], $arSourceSize["width"], $arSourceSize["height"]);
							imagealphablending($picture, true);
						}
						elseif($arSourceFileSizeTmp[2] == IMAGETYPE_GIF)
						{
							imagepalettecopy($picture, $sourceImage);

							//Save transparency for GIFs
							$transparentcolor = imagecolortransparent($sourceImage);
							if($transparentcolor >= 0 && $transparentcolor < imagecolorstotal($sourceImage))
							{
								$RGB = imagecolorsforindex($sourceImage, $transparentcolor);
								$transparentcolor = imagecolorallocate($picture, $RGB["red"], $RGB["green"], $RGB["blue"]);
								imagecolortransparent($picture, $transparentcolor);
								imagefilledrectangle($picture, 0, 0, $arDestinationSize["width"], $arDestinationSize["height"], $transparentcolor);
							}

							imagecopyresampled($picture, $sourceImage,
								0, 0, $arSourceSize["x"], $arSourceSize["y"],
								$arDestinationSize["width"], $arDestinationSize["height"], $arSourceSize["width"], $arSourceSize["height"]);
						}
						else
						{
							imagecopyresampled($picture, $sourceImage,
								0, 0, $arSourceSize["x"], $arSourceSize["y"],
								$arDestinationSize["width"], $arDestinationSize["height"], $arSourceSize["width"], $arSourceSize["height"]);
						}
					}
					else
					{
						$picture = ImageCreate($arDestinationSize["width"], $arDestinationSize["height"]);
						imagecopyresized($picture, $sourceImage,
							0, 0, $arSourceSize["x"], $arSourceSize["y"],
							$arDestinationSize["width"], $arDestinationSize["height"], $arSourceSize["width"], $arSourceSize["height"]);
					}
				}
				else
				{
					$picture = $sourceImage;
				}

				if(is_array($arFilters))
				{
					foreach($arFilters as $arFilter)
						$bNeedCreatePicture |= CFile::ApplyImageFilter($picture, $arFilter, $bHasAlpha);
				}

				if(is_array($arWaterMark))
				{
					$arWaterMark["name"] = "watermark";
					$bNeedCreatePicture |= CFile::ApplyImageFilter($picture, $arWaterMark, $bHasAlpha);
				}

				if ($bNeedCreatePicture)
				{
					if($io->FileExists($destinationFile))
						$io->Delete($destinationFile);
					switch ($arSourceFileSizeTmp[2])
					{
						case IMAGETYPE_GIF:
							imagegif($picture, $io->GetPhysicalName($destinationFile));
							break;
						case IMAGETYPE_PNG:
							imagealphablending($picture, false );
							imagesavealpha($picture, true);
							imagepng($picture, $io->GetPhysicalName($destinationFile));
							break;
						default:
							if ($arSourceFileSizeTmp[2] == IMAGETYPE_BMP)
								$destinationFile .= ".jpg";
							if($jpgQuality === false)
								$jpgQuality = intval(COption::GetOptionString('main', 'image_resize_quality', '95'));
							if($jpgQuality <= 0 || $jpgQuality > 100)
								$jpgQuality = 95;
							imagejpeg($picture, $io->GetPhysicalName($destinationFile), $jpgQuality);
							break;
					}
					imagedestroy($picture);
				}
			}

			return true;
		}

		return false;
	}
Пример #7
0
	function convert_blog_image($p1 = "", $imageId = "", $p2 = "", $type = "html", $serverName="")
	{
		$imageId = IntVal($imageId);
		if($imageId <= 0)
			return;

		$res = "";
		if(IntVal($this->arImages[$imageId]) > 0)
		{
			$this->showedImages[] = $imageId;
			if($f = CBlogImage::GetByID($imageId))
			{
				if(COption::GetOptionString("blog", "use_image_perm", "N") == "N")
				{
					if($db_img_arr = CFile::GetFileArray($this->arImages[$imageId]))
					{
						if(substr($db_img_arr["SRC"], 0, 1) == "/")
							$strImage = $this->serverName.$db_img_arr["SRC"];
						else
							$strImage = $db_img_arr["SRC"];
						$sourceImage = $strImage;

						$strPar = "";
						preg_match("/width\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p1, $width);
						preg_match("/height\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p1, $height);
						$width = intval($width[1]);
						$height = intval($height[1]);

						if($width <= 0)
						{
							preg_match("/width\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p2, $width);
							$width = intval($width[1]);
						}
						if($height <= 0)
						{
							preg_match("/height\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p2, $height);
							$height = intval($height[1]);
						}

						if(IntVal($width) <= 0)
							$width = $db_img_arr["WIDTH"];
						if(IntVal($height) <= 0)
							$height= $db_img_arr["HEIGHT"];

						if($width > $this->imageWidth || $height > $this->imageHeight)
						{
							$arFileTmp = CFile::ResizeImageGet(
								$db_img_arr,
								array("width" => $this->imageWidth, "height" => $this->imageHeight),
								BX_RESIZE_IMAGE_PROPORTIONAL,
								true
							);
							if(substr($arFileTmp["src"], 0, 1) == "/")
								$strImage = $this->serverName.$arFileTmp["src"];
							else
								$strImage = $arFileTmp["src"];
							$width = $arFileTmp["width"];
							$height = $arFileTmp["height"];
						}

						$strPar = ' width="'.$width.'" height="'.$height.'"';
						$strImage = preg_replace("'(?<!:)/+'s", "/", $strImage);
						$sourceImage = preg_replace("'(?<!:)/+'s", "/", $sourceImage);

						if(strlen($this->authorName) > 0)
							$strPar .= " data-bx-title=\"".$this->authorName."\"";

						if ($this->isSonetLog)
						{
							$strImage = preg_replace("'(?<!:)/+'s", "/", $strImage);
							$res = '[IMG]'.$strImage.'[/IMG]';
						}
						else
						{

							if($type == "mail")
								$res = htmlspecialcharsbx($f["TITLE"])." (IMAGE: ".$strImage." )";
							else
								$res = '<img src="'.$strImage.'" title="" alt="'.htmlspecialcharsbx($f["TITLE"]).'" border="0"'.$strPar.' data-bx-image="'.$sourceImage.'" />';
						}
					}
				}
				else
				{
					preg_match("/width\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p1, $width);
					preg_match("/height\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p1, $height);
					$width = intval($width[1]);
					$height = intval($height[1]);

					if($width <= 0)
					{
						preg_match("/width\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p2, $width);
						$width = intval($width[1]);
					}
					if($height <= 0)
					{
						preg_match("/height\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p2, $height);
						$height = intval($height[1]);
					}

					if(IntVal($width) <= 0)
						$width = $this->imageWidth;
					if(IntVal($height) <= 0)
						$height = $this->imageHeight;

					if($width > $this->imageWidth)
						$width = $this->imageWidth;
					if($height > $this->imageHeight)
						$height = $this->imageHeight;

					$strImage = $this->serverName."/bitrix/components/bitrix/blog/show_file.php?fid=".$imageId."&width=".$width."&height=".$height;
					$sourceImage = $this->serverName."/bitrix/components/bitrix/blog/show_file.php?fid=".$imageId;

					$db_img_arr = CFile::GetFileArray($this->arImages[$imageId]);

					CFile::ScaleImage($db_img_arr["WIDTH"], $db_img_arr["HEIGHT"], Array("width" => $width, "height" => $height), BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);

					if ($this->isSonetLog)
					{
						$strImage = preg_replace("'(?<!:)/+'s", "/", $strImage);
						$res = '[IMG]'.$strImage.'[/IMG]';
					}
					else
					{
						if($type == "mail")
							$res = htmlspecialcharsbx($f["TITLE"])." (IMAGE: ".$strImage." )";
						else
						{
							$strPar = ' width="'.$arDestinationSize["width"].'" height="'.$arDestinationSize["height"].'"';
							if(strlen($this->authorName) > 0)
								$strPar .= " data-bx-title=\"".$this->authorName."\"";

							$res = '<img src="'.$strImage.'" title="" alt="'.htmlspecialcharsbx($f["TITLE"]).'" border="0" data-bx-image="'.$sourceImage.'"'.$strPar.' />';
							if(!empty($this->blogImageSizeEvents))
							{
								foreach($this->blogImageSizeEvents as $arEvent)
									ExecuteModuleEventEx($arEvent, Array(&$res, $strImage, $db_img_arr, $f, $arDestinationSize));
							}
						}
					}
				}
				return $res;
			}
		}
		return $res;
	}
Пример #8
0
 function OnAfterResizeImage($arFile, $arResizeParams, &$callbackData, &$cacheImageFile, &$cacheImageFileTmp, &$arImageSize)
 {
     global $arCloudImageSizeCache;
     $io = CBXVirtualIo::GetInstance();
     if (!is_array($callbackData)) {
         return false;
     }
     if ($callbackData["cacheSTARTED"]) {
         if (isset($callbackData["tmpFile"])) {
             $arFileToStore = CFile::MakeFileArray($io->GetPhysicalName($cacheImageFileTmp));
             if ($callbackData["obTargetBucket"]->SaveFile($callbackData["fileURL"], $arFileToStore)) {
                 $cacheImageFile = $callbackData["obTargetBucket"]->GetFileSRC($callbackData["fileURL"]);
                 $arImageSize = CFile::GetImageSize($cacheImageFileTmp);
                 $arImageSize[2] = filesize($io->GetPhysicalName($cacheImageFileTmp));
                 $iFileSize = filesize($arFileToStore["tmp_name"]);
                 if (!is_array($arImageSize)) {
                     $arImageSize = array(0, 0);
                 }
                 $callbackData["cacheOBJ"]->EndDataCache(array("cacheImageFile" => $cacheImageFile, "width" => $arImageSize[0], "height" => $arImageSize[1], "size" => $arImageSize[2]));
                 $tmpFile = $io->GetPhysicalName($callbackData["tmpFile"]);
                 unlink($tmpFile);
                 @rmdir(substr($tmpFile, 0, -strlen(bx_basename($tmpFile))));
                 $arCloudImageSizeCache[$cacheImageFile] = $arImageSize;
                 $callbackData["obTargetBucket"]->IncFileCounter($iFileSize);
                 return true;
             } else {
                 $callbackData["cacheOBJ"]->AbortDataCache();
                 $tmpFile = $io->GetPhysicalName($callbackData["tmpFile"]);
                 unlink($tmpFile);
                 @rmdir(substr($tmpFile, 0, -strlen(bx_basename($tmpFile))));
                 unlink($cacheImageFileTmp);
                 @rmdir(substr($cacheImageFileTmp, 0, -strlen(bx_basename($cacheImageFileTmp))));
                 // $cacheImageFile not clear what to do
                 return false;
             }
         } else {
             CFile::ScaleImage($arFile["WIDTH"], $arFile["HEIGHT"], $arResizeParams[0], $arResizeParams[1], $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
             $cacheImageFile = $callbackData["obTargetBucket"]->GetFileSRC($callbackData["fileURL"]);
             $arImageSize = array($arDestinationSize["width"], $arDestinationSize["height"], isset($callbackData["fileSize"]) ? $callbackData["fileSize"] : $callbackData["obTargetBucket"]->GetFileSize($callbackData["fileURL"]));
             $callbackData["cacheOBJ"]->EndDataCache(array("cacheImageFile" => $cacheImageFile, "width" => $arImageSize[0], "height" => $arImageSize[1], "size" => $arImageSize[2]));
             $arCloudImageSizeCache[$cacheImageFile] = $arImageSize;
             return true;
         }
     } elseif (is_array($callbackData["cacheVARS"])) {
         $cacheImageFile = $callbackData["cacheVARS"]["cacheImageFile"];
         $arImageSize = array($callbackData["cacheVARS"]["width"], $callbackData["cacheVARS"]["height"], $callbackData["cacheVARS"]["size"]);
         $arCloudImageSizeCache[$cacheImageFile] = $arImageSize;
         return true;
     }
     return false;
 }
Пример #9
0
                 $circumscribed = $circumscribed1;
             }
         }
         if ($bExactly && $circumscribed) {
             CFile::ScaleImage($arSize["width"], $arSize["height"], $circumscribed, BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture, $arSourceSize, $arSize);
         }
         $file["INLINE"]["width"] = $bExactly ? $arSize["width"] : $arDestinationSize["width"];
         $file["INLINE"]["height"] = $bExactly ? $arSize["height"] : $arDestinationSize["height"];
         // gallery
         $max_real_dimension = max(array(intval($file["IMAGE"]["WIDTH"]), intval($file["IMAGE"]["HEIGHT"])));
         if ($max_real_dimension > $max_dimension) {
             $arParams["SCREEN_SIZE"] = array("width" => $max_dimension, "height" => $max_dimension);
         } else {
             $arParams["SCREEN_SIZE"] = array("width" => $max_real_dimension, "height" => $max_real_dimension);
         }
         CFile::ScaleImage($file["IMAGE"]["WIDTH"], $file["IMAGE"]["HEIGHT"], $arParams["SCREEN_SIZE"], BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
         if ($bNeedCreatePicture) {
             $arParams["SCREEN_SIZE"]["signature"] = \Bitrix\Disk\Security\ParameterSigner::getImageSignature($file["ID"], $arParams["SCREEN_SIZE"]["width"], $arParams["SCREEN_SIZE"]["height"]);
             $file["BASIC"]["src"] .= "&" . http_build_query($arParams["SCREEN_SIZE"]);
             $file["BASIC"]["width"] = $arDestinationSize["width"];
             $file["BASIC"]["height"] = $arDestinationSize["height"];
         }
         $arResult["FILES"][$id] = $images[$id] = $file;
     } else {
         $arResult["FILES"][$id] = $files[$id] = $file;
     }
 }
 if ($this->__page == "show") {
     $arResult['IMAGES'] = $images;
     $arResult['FILES'] = $files;
 }
Пример #10
0
$arParams["MODE"] = trim($arParams["MODE"]);
// *************************/ADDITIONAL ****************************************************************
// *************************/Input params***************************************************************
$img = array("~src" => $arParams["URL"], "src_download" => $arParams["URL"] . (strpos($arParams["URL"], '?') !== false ? '&' : '?') . "force_download=1", "src" => $arParams["URL"] . (strpos($arParams["URL"], '?') !== false ? '&' : '?') . http_build_query($arParams["MAX_SIZE"]), "~width" => $arParams["IMG_WIDTH"], "width" => $arParams["IMG_WIDTH"], "~height" => $arParams["IMG_HEIGHT"], "height" => $arParams["IMG_HEIGHT"]);
CFile::ScaleImage($arParams["IMG_WIDTH"], $arParams["IMG_HEIGHT"], $arParams["MAX_SIZE"], BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
$circumscribed = $arParams["MAX_SIZE"];
if ($arParams["HTML_SIZE"]) {
    CFile::ScaleImage($arParams["IMG_WIDTH"], $arParams["IMG_HEIGHT"], $arParams["HTML_SIZE"], BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture1, $arSourceSize, $arDestinationSize1);
    if ($bNeedCreatePicture1 && ($arDestinationSize1["width"] < $arDestinationSize["width"] || $arDestinationSize1["height"] < $arDestinationSize["height"])) {
        $bNeedCreatePicture = true;
        $circumscribed = $arParams["HTML_SIZE"];
        $arDestinationSize = $arDestinationSize1;
    }
}
if ($bExactly) {
    CFile::ScaleImage($arParams["SIZE"]["width"], $arParams["SIZE"]["height"], $circumscribed, BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture1, $arSourceSize, $arDestinationSize1);
    if ($bNeedCreatePicture1) {
        $bNeedCreatePicture = true;
        $arDestinationSize = $arDestinationSize1;
    }
}
if ($bNeedCreatePicture) {
    $img["width"] = $arDestinationSize["width"];
    $img["height"] = $arDestinationSize["height"];
}
if ($arParams['MODE'] == 'RSS') {
    ob_start();
    if (!$bNeedCreatePicture) {
        ?>
<img src="<?php 
        echo $img["src"];