-
Code's Tags
-
Your Codes
-
Reffers
-
Linked Codes
|
Code:
Short link for Twitter:
HTML:
HTML view:
Copy Source | Copy HTML- <?define("SM_SAFE_MODE", true); require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
-
- function CustomResizePicture($arFile, $arResize)
- {
- global $APPLICATION;
- $APPLICATION->RestartBuffer();
-
-
- if(strlen($arFile["tmp_name"]) <= 0)
- return $arFile;
-
- if(array_key_exists("error", $arFile) && $arFile["error"] !== 0)
- return GetMessage("IBLOCK_BAD_FILE_ERROR");
-
- $file = $arFile["tmp_name"];
-
- if(!file_exists($file) && !is_file($file))
- return GetMessage("IBLOCK_BAD_FILE_NOT_FOUND");
-
- $width = intval($arResize["WIDTH"]);
- $height = intval($arResize["HEIGHT"]);
-
-
- if($width <= 0 && $height <= 0)
- return $arFile;
-
- $orig = @getimagesize($file);
- if(!is_array($orig))
- return GetMessage("IBLOCK_BAD_FILE_NOT_PICTURE");
-
- if(($width > 0 ) || ($height > 0 ))
- {
- $width_orig = $orig[ 0];
- $height_orig = $orig[1];
-
- if($width <= 0)
- {
- $width = $width_orig;
- }
-
- if($height <= 0)
- {
- $height = $height_orig;
- }
- //if($width_orig > $width)
- //{
- // $height = ($width / $width_orig) * $height_orig;
- //}
-
- //if($height_orig > $height)
- //{
- // $width = ($height / $height_orig) * $width_orig;
- //}
-
- $height_1 = ($width / $width_orig) * $height_orig;
- $width_1 = ($height_1 / $height_orig) * $width_orig;
-
-
- $width_2 = ($height / $height_orig) * $width_orig;
- $height_2 = ($width_2 / $width_orig) * $height_orig;
-
-
- //echo 'h:'.$height_1.' w:'.$width_1.'<br />';
- //echo 'h:'.$height_2.' w:'.$width_2;
-
- if( $height_1<=$height && $width_1<=$width)
- { $height = $height_1; $width = $width_1; }
- else
- { $height = $height_2; $width = $width_2; }
-
- //die();
-
-
- $image_type = $orig[2];
- if($image_type == IMAGETYPE_JPEG)
- $image = imagecreatefromjpeg($file);
- elseif($image_type == IMAGETYPE_GIF)
- $image = imagecreatefromgif($file);
- elseif($image_type == IMAGETYPE_PNG)
- $image = imagecreatefrompng($file);
- else
- return false/*GetMessage("IBLOCK_BAD_FILE_UNSUPPORTED")*/;
-
- $image_p = imagecreatetruecolor($width, $height);
-
-
- if($image_type == IMAGETYPE_JPEG)
- {
-
- header("Content-type: image/jpeg");
- header("Pragma: public");//может кешироватьÑÑ Ð²Ñеми (прокÑи-Ñерверами тоже)
- header("Cache-Control: max-age=3600");//закешировать на Ñто времÑ
-
-
- if($arResize["METHOD"] === "resample")
- imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
- else
- imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
-
- if($arResize["COMPRESSION"] > 0)
- imagejpeg($image_p, false, $arResize["COMPRESSION"]);
- else
- imagejpeg($image_p/*, $file*/);
- }
- elseif($image_type == IMAGETYPE_GIF && function_exists("imagegif"))
- {
-
- header("Content-type: image/gif");
- header("Pragma: public");//может кешироватьÑÑ Ð²Ñеми (прокÑи-Ñерверами тоже)
- header("Cache-Control: max-age=3600");//закешировать на Ñто времÑ
-
-
- imagetruecolortopalette($image_p, true, imagecolorstotal($image));
- imagepalettecopy($image_p, $image);
-
- //Save transparency for GIFs
- $transparentcolor = imagecolortransparent($image);
- if($transparentcolor >= 0 && $transparentcolor < imagecolorstotal($image))
- {
- $transparentcolor = imagecolortransparent($image_p, $transparentcolor);
- imagefilledrectangle($image_p, 0, 0, $width, $height, $transparentcolor);
- }
-
- if($arResize["METHOD"] === "resample")
- imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
- else
- imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
- imagegif($image_p/*, $file*/);
- }
- else
- {
-
- header("Content-type: image/png");
- header("Pragma: public");//может кешироватьÑÑ Ð²Ñеми (прокÑи-Ñерверами тоже)
- header("Cache-Control: max-age=3600");//закешировать на Ñто времÑ
-
-
- //Save transparency for PNG
- $transparentcolor = imagecolorallocate($image_p, 0, 0, 0);
- $transparentcolor = imagecolortransparent($image_p, $transparentcolor);
- imagealphablending($image_p, false);
- imagesavealpha($image_p, true);
-
- if($arResize["METHOD"] === "resample")
- imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
- else
- imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
-
- imagepng($image_p/*, $file*/);
- }
-
-
-
-
- imagedestroy($image);
- imagedestroy($image_p);
-
- /*$arFile["size"] = filesize($file);*/
- return $arFile;
- }
-
- }
-
- $width = intval( $_GET['w'] );
- $height = intval( $_GET['h'] );
- $image_id = intval( $_GET['i'] );
-
- CustomResizePicture( CFile::MakeFileArray($image_id), array(
- "WIDTH" => $width,
- "HEIGHT" => $height,
- "METHOD" => "resample",
- 'COMPRESSION' => '100',
- )
- );
-
-
- require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");?>
|