| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @package Dolphin Core |
|---|
| 4 | * @copyright Copyright (c) BoonEx Pty Limited - http://www.boonex.com/ |
|---|
| 5 | * @license CC-BY - http://creativecommons.org/licenses/by/3.0/ |
|---|
| 6 | */ |
|---|
| 7 | defined('BX_DOL') or die('hack attempt'); |
|---|
| 8 | |
|---|
| 9 | $gdInstalled = extension_loaded( 'gd' ); |
|---|
| 10 | $use_gd = getParam( 'enable_gd' ) == 'on' ? 1 : 0; |
|---|
| 11 | |
|---|
| 12 | /** |
|---|
| 13 | * Resizes image given in $srcFilename to dimensions specified with $sizeX x $sizeY and |
|---|
| 14 | * saves it to $dstFilename |
|---|
| 15 | * |
|---|
| 16 | * @param string $srcFilename - source image filename |
|---|
| 17 | * @param string $dstFilename - destination image filename |
|---|
| 18 | * @param int $sizeX - width of destination image |
|---|
| 19 | * @param int $sizeY - height of destination image |
|---|
| 20 | * @param bool $forceJPGOutput - always make result in JPG format |
|---|
| 21 | * |
|---|
| 22 | * @return int - zero on success, non-zero on fail |
|---|
| 23 | * |
|---|
| 24 | * |
|---|
| 25 | * NOTE: Source image should be in GIF, JPEG or PNG format |
|---|
| 26 | */ |
|---|
| 27 | function imageResize( $srcFilename, $dstFilename, $sizeX, $sizeY, $forceJPGOutput = false ) |
|---|
| 28 | { |
|---|
| 29 | bx_import ('BxDolImageResize'); |
|---|
| 30 | $o =& BxDolImageResize::getInstance(); |
|---|
| 31 | $o->removeCropOptions (); |
|---|
| 32 | $o->setJpegOutput ($forceJPGOutput); |
|---|
| 33 | $o->setSize ($sizeX, $sizeY); |
|---|
| 34 | if ((($sizeX == 32) && (32 == $sizeY)) || (($sizeX == 64) && (64 == $sizeY))) |
|---|
| 35 | $o->setSquareResize (true); |
|---|
| 36 | else |
|---|
| 37 | $o->setSquareResize (false); |
|---|
| 38 | return $o->resize($srcFilename, $dstFilename); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | /** |
|---|
| 42 | * Applies watermark to image given in $srcFilename with specified opacity and saves result |
|---|
| 43 | * to $dstFilename |
|---|
| 44 | * |
|---|
| 45 | * @param string $srcFilename - source image filename |
|---|
| 46 | * @param string $dstFilename - destination image filename |
|---|
| 47 | * @param string $wtrFilename - watermark filename |
|---|
| 48 | * @param int $wtrTransparency - watermark transparency (from 0 to 100) |
|---|
| 49 | * |
|---|
| 50 | * @return int - zero on success, non-zero on fail |
|---|
| 51 | * |
|---|
| 52 | * |
|---|
| 53 | * NOTE: Source image should be in GIF, JPEG or PNG format |
|---|
| 54 | * NOTE: if $wtrTransparency = 0 then no action will be done with source image |
|---|
| 55 | * but if $wtrTransparency = 100 then watermark will fully override source image |
|---|
| 56 | */ |
|---|
| 57 | function applyWatermark( $srcFilename, $dstFilename, $wtrFilename, $wtrTransparency ) |
|---|
| 58 | { |
|---|
| 59 | bx_import ('BxDolImageResize'); |
|---|
| 60 | $o =& BxDolImageResize::getInstance(); |
|---|
| 61 | return $o->applyWatermark ($srcFilename, $dstFilename, $wtrFilename, $wtrTransparency); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | /** |
|---|
| 65 | * Moves and resize uploaded file |
|---|
| 66 | * |
|---|
| 67 | * @param array $_FILES - system array of uploaded files |
|---|
| 68 | * @param string $fname - name of "file" form |
|---|
| 69 | * @param string $path_and_name - path and name of new file to create |
|---|
| 70 | * @param string $maxsize - max available size (optional) |
|---|
| 71 | * @param boolean $imResize - call imageResize function immediately (optional) |
|---|
| 72 | |
|---|
| 73 | * |
|---|
| 74 | * @return int in case of error and extention of new file |
|---|
| 75 | * in case of success |
|---|
| 76 | * |
|---|
| 77 | * NOTE: Source image should be in GIF, JPEG, PNG or BMP format |
|---|
| 78 | */ |
|---|
| 79 | function moveUploadedImage( $_FILES, $fname, $path_and_name, $maxsize='', $imResize='true' ) |
|---|
| 80 | { |
|---|
| 81 | global $max_photo_height; |
|---|
| 82 | global $max_photo_width; |
|---|
| 83 | |
|---|
| 84 | $height = $max_photo_height; |
|---|
| 85 | if ( !$height ) |
|---|
| 86 | $height = 400; |
|---|
| 87 | $width = $max_photo_width; |
|---|
| 88 | if ( !$width ) |
|---|
| 89 | $width = 400; |
|---|
| 90 | |
|---|
| 91 | if ( $maxsize && ($_FILES[$fname]['size'] > $maxsize || $_FILES[$fname]['size'] == 0) ) |
|---|
| 92 | { |
|---|
| 93 | if ( file_exists($_FILES[$fname]['tmp_name']) ) |
|---|
| 94 | { |
|---|
| 95 | unlink($_FILES[$fname]['tmp_name']); |
|---|
| 96 | } |
|---|
| 97 | return false; |
|---|
| 98 | } |
|---|
| 99 | else |
|---|
| 100 | { |
|---|
| 101 | $scan = getimagesize($_FILES[$fname]['tmp_name']); |
|---|
| 102 | |
|---|
| 103 | if ( ($scan['mime'] == 'image/jpeg' && $ext = '.jpg' ) || |
|---|
| 104 | ( $scan['mime'] == 'image/gif' && $ext = '.gif' ) || |
|---|
| 105 | ( $scan['mime'] == 'image/png' && $ext = '.png' ) ) //deleted .bmp format |
|---|
| 106 | { |
|---|
| 107 | |
|---|
| 108 | $path_and_name .= $ext; |
|---|
| 109 | move_uploaded_file( $_FILES[$fname]['tmp_name'], $path_and_name ); |
|---|
| 110 | |
|---|
| 111 | if ( $imResize ) |
|---|
| 112 | imageResize( $path_and_name, $path_and_name, $width, $height ); |
|---|
| 113 | |
|---|
| 114 | } |
|---|
| 115 | else |
|---|
| 116 | { |
|---|
| 117 | return IMAGE_ERROR_WRONG_TYPE; |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | return $ext; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | function ResizeAnyPromo($sFromPath, $sToPath, $iChmod = 0644) { |
|---|
| 125 | $iDefWidth = (int)getParam('promoWidth'); |
|---|
| 126 | if($iDefWidth == 0) |
|---|
| 127 | $iDefWidth = 960; |
|---|
| 128 | |
|---|
| 129 | imageResize($sFromPath, $sToPath, $iDefWidth, $iDefWidth); |
|---|
| 130 | chmod( $sToPath, $iChmod ); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | function ResizeAllPromos() { |
|---|
| 134 | $sRprPromoPath = BxDolConfig::getInstance()->get('path_dynamic', 'rpr_images_promo'); |
|---|
| 135 | |
|---|
| 136 | //cleaning old |
|---|
| 137 | $sDestFold = $sRprPromoPath; |
|---|
| 138 | $rDir = opendir($sDestFold); |
|---|
| 139 | if($rDir) { |
|---|
| 140 | while(($sFile = readdir($rDir)) !== false) { |
|---|
| 141 | if($sFile == '.' || $sFile == '..' || !is_file($sDestFold . $sFile)) |
|---|
| 142 | continue; |
|---|
| 143 | @unlink($sDestFold . $sFile); |
|---|
| 144 | } |
|---|
| 145 | closedir($rDir); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | //inserting new |
|---|
| 149 | $iImgCnt = 1; |
|---|
| 150 | $sDestFold = $sRprPromoPath; |
|---|
| 151 | $rDir = opendir($sDestFold); |
|---|
| 152 | if($rDir) { |
|---|
| 153 | while(($sFile = readdir($rDir)) !== false) { |
|---|
| 154 | if($sFile == '.' || $sFile == '..' || !is_file($sDestFold . $sFile)) |
|---|
| 155 | continue; |
|---|
| 156 | ResizeAnyPromo($sDestFold . $sFile, $sRprPromoPath . $sFile); |
|---|
| 157 | $iImgCnt++; |
|---|
| 158 | } |
|---|
| 159 | closedir($rDir); |
|---|
| 160 | } |
|---|
| 161 | } |
|---|