Tag Archives: source
Install PHP-Screw 1.5 on openSUSE

1. Download & Prepare
1 2 3 4 5 6 7 |
cd /usr/local/src wget -O php_screw-1.5.tar.gz http://downloads.sourceforge.net/project/php-screw/php-screw/1.5/php_screw-1.5.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fphp-screw%2F tar -zxvf php_screw-1.5.tar.gz cd php_screw-1.5 /usr/bin/phpize |
2. Change encryption seed
1 2 |
vi my_screw.h # change seed to your random value |
3. Compile module
1 2 |
./configure --with-php-config=/usr/bin/php-config make |
If you get error with below message… Comment out 124 & 133 lines those include CG(extended_info) = 1; in php_screw.c Then try compile again. php_screw-1.5/php_screw.c:133: error: ‘struct _zend_compiler_globals’ has no member named ‘extended_info’ 4. Add module to php & restart
1 2 3 4 5 6 7 8 9 10 |
ls ./modules cp modules/php_screw.so /usr/lib64/php5/extensions/ vi /etc/php5/conf.d/php_screw.ini # insert below line extension=php_screw.so service apache2 restart php -i | grep php_screw # check module is activated |
5. Compile encryption utility
1 2 3 4 5 |
cd tools/ make cp screw /usr/local/bin chmod 400 /usr/local/src/php_screw-1.5/my_screw.h |
♦ Usage of encryption
1 2 |
cd /srv/www/htdocs screw index.php |
♦ References https://www.linux.co.kr/home2/board/subbs/board.php?bo_table=lecture&wr_id=1727 http://jswlinux.tistory.com/entry/PHP-Screw-%EC%BB%B4%ED%8C%8C%EC%9D%BC%EC%8B%9C-%EC%97%90%EB%9F%AC%EB%82%A0-%EB%95%8C http://sourceforge.net/projects/php-screw/
[PHP5] Thumbnail Class
원래 십여년전(?)부터 뜯어고쳐 오며 사용하던 소스를 좀 정리했다. 이전에 GD를 직접 컨트롤 했었는데 조금 찾아보니 WideImage 란 라리브러리가 있기에, 그걸로 바꾸다보니 워낙 기능이 막강해서 정작 내가 만든 클래스는 Wrapping Class가 되어 버렸다 ;; 어쨋든, 밤하늘의 별처럼 널려있는 썸네일 라이브러리들을 마다하고 만든 이유는 단 두가지 이다. 썸네일의 종횡비율에 따라 중앙부분을 기준으로 Crop해서 썸네일을 만들어 주는 기능 PNG포맷에서 Resizing시 원본의 Alpha Channel을 유지 해 주는 기능 그 이외에는 잡다한 기능을 다 빼 버렸다. 복잡해지면 오래 못쓰므로… Licence : GNU LGPL 2.1 Copyright (C) 2013 Aiden, Kihyun Kim.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
if (!class_exists('WideImage')) require_once('WideImage/WideImage.php'); /** * Thumbnail * * @category Thumbnail * @package Thumbnail * @copyright 2013 Aiden Kim * @license GNU LGPL 2.1. */ class Thumbnail { const FIT_INSIDE = 'inside'; const FIT_INSIDE_CROP = 'inside-crop'; const FIT_OUTSIDE = 'outside'; const FIT_FILL = 'fill'; const IMAGETYPE_PNG = IMAGETYPE_PNG; const IMAGETYPE_JPEG = IMAGETYPE_JPEG; const IMAGETYPE_GIF = IMAGETYPE_GIF; const IMAGETYPE_BMP = IMAGETYPE_BMP; const IMAGETYPE_ICO = IMAGETYPE_ICO; const IMAGETYPE_AUTO = -1; static public $ImgExts = array( self::IMAGETYPE_PNG => 'png' ,self::IMAGETYPE_JPEG => 'jpg' ,self::IMAGETYPE_GIF => 'gif' ,self::IMAGETYPE_BMP => 'bmp' ,self::IMAGETYPE_ICO => 'ico' ); private $orgImg = null; private $orgImgPath = null; private $prop = array( 'ouputType' => self::IMAGETYPE_AUTO ,'outputWidth' => 120 ,'outputHeight' => 120 ,'ouputFit' => self::FIT_INSIDE ,'useTransparent' => true ,'jpegQuality' => 95 // 1~100 (100 is best) ,'pngCompress' => 3 // 1~9 (1 is best) ,'fileChmod' => -1 ); public function __construct($imgPath=null) { if ($imgPath) { $this->load($imgPath); } } public function __destruct() { if ($this->orgImg && method_exists($this->orgImg,'destroy')) @$this->orgImg->destroy(); unset($this->orgImg); } public function __set($name, $value) { switch ($name) { case 'useTransparent': $this->prop[$name] = ($value ? true : false); break; case 'ouputFit': $this->prop[$name] = strval($value); break; case 'ouputType': if (array_key_exists(intval($value), self::$ImgExts)) $this->prop[$name] = intval($value); break; case 'outputWidth': case 'outputHeight': case 'useTransparent': case 'jpegQuality': case 'pngCompress': case 'fileChmod': $this->prop[$name] = intval($value); break; } } public function __get($name) { switch ($name) { case 'imgIsValid': if ($this->orgImg) { return $this->orgImg->isValid(); } return false; case 'imgWidth': if ($this->orgImg) { return $this->orgImg->getWidth(); } return false; case 'imgHeight': if ($this->orgImg) { return $this->orgImg->getHeight(); } return false; default: if (array_key_exists($name, $this->prop)) { return $this->prop[$name]; } } $trace = debug_backtrace(); trigger_error( 'Undefined property via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE); return null; } /** * Load original image file * * @param string $imgPath path or url of image file * @return boolean results */ public function load($imgPath) { $this->orgImgPath = $imgPath; $this->orgImg = WideImage::loadFromFile($imgPath); if ((is_null($this->orgImg)) || (!method_exists($this->orgImg,'isValid')) || (!$this->orgImg->isValid())) { $this->orgImg = null; $trace = debug_backtrace(); trigger_error( 'Unable to load image file via load(): ' . $imgPath . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE); return false; } if (($this->orgImg->isTransparent() || $this->orgImg->isTrueColor()) && $this->useTransparent) { $this->orgImg->alphaBlending = false; } return true; } /** * Create thumbnail automatically * * @param string|null $imgPath path or url of image file * @return WideImage_Image thumbnail image handler */ public function createThumbnail($imgPath=null) { if (!is_null($imgPath)) $this->load($imgPath); if (!$this->orgImg) return false; if ($this->ouputFit == self::FIT_INSIDE_CROP) { $imgRatio = $this->imgWidth / $this->imgHeight; $thumbRatio = $this->outputWidth / $this->outputHeight; if ($imgRatio > $thumbRatio) { $cropWidth = $this->imgHeight * $this->outputWidth / $this->outputHeight; $cropHeight = $this->imgHeight; $cropLeft = round(($this->imgWidth - $cropWidth) / 2); $cropTop = 0; }else if ($imgRatio < $thumbRatio) { $cropWidth = $this->imgWidth; $cropHeight = $this->imgWidth * $this->outputHeight / $this->outputWidth; $cropLeft = 0; $cropTop = round(($this->imgHeight - $cropHeight) / 2); }else{ $cropWidth = $this->imgWidth; $cropHeight = $this->imgHeight; $cropLeft = 0; $cropTop = 0; } return $this->createCropThumbnail($cropLeft, $cropTop, $cropWidth, $cropHeight); }else{ $thumbImg = $this->orgImg->resizeDown($this->outputWidth, $this->outputHeight, $this->ouputFit); if ((!is_null($thumbImg)) && (method_exists($thumbImg,'isValid')) && ($thumbImg->isValid())) { if (($thumbImg->isTransparent() || $thumbImg->isTrueColor()) && $this->useTransparent) $thumbImg->alphaBlending = false; return $thumbImg; } } return false; } /** * Create thumbnail manually * * @param int|0 $cropLeft crop position x * @param int|0 $cropTop crop position y * @param int|0 $cropWidth crop width * @param int|0 $cropHeight crop height * @param string|null $imgPath path or url of image file * @return WideImage_Image thumbnail image handler */ public function createCropThumbnail($cropLeft=0, $cropTop=0, $cropWidth=0, $cropHeight=0, $imgPath=null) { if (($cropWidth <= 0) || ($cropHeight <= 0)) return $this->createThumbnail($imgPath); if (!is_null($imgPath)) $this->load($imgPath); if (!$this->orgImg) return false; // Crop $cropedImg = $this->orgImg->crop($cropLeft, $cropTop, $cropWidth, $cropHeight); if ((!is_null($cropedImg)) && (method_exists($cropedImg,'isValid')) && ($cropedImg->isValid())) { try { if (($cropedImg->isTransparent() || $cropedImg->isTrueColor()) && $this->useTransparent) $cropedImg->alphaBlending = false; // Resize $thumbImg = $cropedImg->resizeDown($this->outputWidth, $this->outputHeight, self::FIT_FILL); @$cropedImg->destroy(); unset($cropedImg); if ((!is_null($thumbImg)) && (method_exists($thumbImg,'isValid')) && ($thumbImg->isValid())) { if (($thumbImg->isTransparent() || $thumbImg->isTrueColor()) && $this->useTransparent) $thumbImg->alphaBlending = false; return $thumbImg; } } catch (Exception $e) { @$cropedImg->destroy(); unset($cropedImg); trigger_error( 'Caught the error: ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() , E_USER_NOTICE); } } return false; } /** * Save thumbnail to file * * @param WideImage_Image $thumbImg thumbnail image handler * @param string $thumbPath save path of thumbnail file * @param int|0 $thumbType image type of thumbnail file * @return string saved file name */ public function saveThumbnail($thumbImg, $thumbPath, $thumbType=null) { if ($thumbImg && $thumbImg->isValid()) { try { if (!is_null($thumbType)) $this->ouputType = $thumbType; if ($this->ouputType == self::IMAGETYPE_AUTO) { $thumbType = self::GetImgTypeFromPath($thumbPath); if ($thumbType !== false) { if ($thumbType === self::IMAGETYPE_PNG) { $thumbImg->saveAlpha = true; $thumbImg->saveToFile($thumbPath, $this->pngCompress); }else if ($thumbType === self::IMAGETYPE_JPEG) { $thumbImg->saveToFile($thumbPath, $this->jpegQuality); }else{ $thumbImg->saveToFile($thumbPath); } } }else{ $thumbType = $this->ouputType; $thumbPath = self::ReplaceExtByImgType($thumbPath, $thumbType); if ($thumbPath !== false) { if ($thumbType === self::IMAGETYPE_PNG) { $thumbImg->saveAlpha = true; $thumbImg->saveToFile($thumbPath, $this->pngCompress); }else if ($thumbType === self::IMAGETYPE_JPEG) { $thumbImg->saveToFile($thumbPath, $this->jpegQuality); }else{ $thumbImg->saveToFile($thumbPath); } } } if ($this->fileChmod >= 0) @chmod($thumbPath, $this->fileChmod); @$thumbImg->destroy(); unset($thumbImg); return basename($thumbPath); } catch (Exception $e) { @$thumbImg->destroy(); unset($thumbImg); trigger_error( 'Caught the error: ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() , E_USER_NOTICE); } } return false; } /** * Output image to browser * * @param WideImage_Image $thumbImg thumbnail image handler * @param int|0 $thumbType image type of thumbnail file * @return boolean results */ public function responseThumbnail($thumbImg, $thumbType=null) { if ($thumbImg && $thumbImg->isValid()) { try { if (!is_null($thumbType)) $this->ouputType = $thumbType; if ($this->ouputType == self::IMAGETYPE_JPEG) { $thumbImg->output(strtolower(self::$ImgExts[$this->ouputType]), $this->jpegQuality); }else if ($this->ouputType == self::IMAGETYPE_GIF) { $thumbImg->output(strtolower(self::$ImgExts[$this->ouputType])); }else if (($this->ouputType == self::IMAGETYPE_PNG) || ($this->ouputType == self::IMAGETYPE_AUTO)) { $thumbImg->output(strtolower(self::$ImgExts[self::IMAGETYPE_PNG]), $this->pngCompress); }else if (array_key_exists($this->ouputType, self::$ImgExts)) { $thumbImg->output(strtolower(self::$ImgExts[$this->ouputType])); } @$thumbImg->destroy(); unset($thumbImg); return true; } catch (Exception $e) { @$thumbImg->destroy(); unset($thumbImg); trigger_error( 'Caught the error: ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() , E_USER_NOTICE); } } return false; } /** * Save thumbnail to file automatically * * @param string $thumbPath save path of thumbnail file * @param string|null $imgPath path or url of image file * @param int|null $thumbWidth thumbnail width * @param int|null $thumbHeight thumbnail height * @param string|null $thumbFit thumbnail fit type * @param int|null $thumbType image type of thumbnail file * @param boolean|null $transparent allow transparent * @param int|null $jpegQuality jpeg quality 1~100 (100 is best) * @param int|null $pngCompress png compress level 1~9 (1 is best) * @return string saved file name */ public function createThumbnailFile($thumbPath, $imgPath=null, $thumbWidth=null, $thumbHeight=null, $thumbFit=null, $thumbType=null, $transparent=null, $jpegQuality=null, $pngCompress=null ) { if (!is_null($thumbWidth)) $this->outputWidth = $thumbWidth; if (!is_null($thumbHeight)) $this->outputHeight = $thumbHeight; if (!is_null($thumbFit)) $this->ouputFit = $thumbFit; if (!is_null($thumbType)) $this->ouputType = $thumbType; if (!is_null($transparent)) $this->useTransparent = $transparent; if (!is_null($jpegQuality)) $this->jpegQuality = $jpegQuality; if (!is_null($pngCompress)) $this->pngCompress = $pngCompress; if (!is_null($imgPath)) $this->load($imgPath); $thumbImg = $this->createThumbnail(); if (!$thumbImg) return false; return $this->saveThumbnail($thumbImg, $thumbPath); } /** * Save thumbnail to file manually * * @param string $thumbPath save path of thumbnail file * @param int $cropLeft crop position x * @param int $cropTop crop position y * @param int $cropWidth crop width * @param int $cropHeight crop height * @param string|null $imgPath path or url of image file * @param int|null $thumbWidth thumbnail width * @param int|null $thumbHeight thumbnail height * @param string|null $thumbFit thumbnail fit type * @param int|null $thumbType image type of thumbnail file * @param boolean|null $transparent allow transparent * @param int|null $jpegQuality jpeg quality 1~100 (100 is best) * @param int|null $pngCompress png compress level 1~9 (1 is best) * @return string saved file name */ public function createCropThumbnailFile($thumbPath, $cropLeft, $cropTop, $cropWidth, $cropHeight, $imgPath=null, $thumbWidth=null, $thumbHeight=null, $thumbFit=null, $thumbType=null, $transparent=null, $jpegQuality=null, $pngCompress=null ) { if (!is_null($thumbWidth)) $this->outputWidth = $thumbWidth; if (!is_null($thumbHeight)) $this->outputHeight = $thumbHeight; if (!is_null($thumbFit)) $this->ouputFit = $thumbFit; if (!is_null($thumbType)) $this->ouputType = $thumbType; if (!is_null($transparent)) $this->useTransparent = $transparent; if (!is_null($jpegQuality)) $this->jpegQuality = $jpegQuality; if (!is_null($pngCompress)) $this->pngCompress = $pngCompress; if (!is_null($imgPath)) $this->load($imgPath); $thumbImg = $this->createCropThumbnail($cropLeft, $cropTop, $cropWidth, $cropHeight); if (!$thumbImg) return false; return $this->saveThumbnail($thumbImg, $thumbPath); } /** * Get image type from path * * @param string $path image path * @return int image type */ static public function GetImgTypeFromPath($path) { $path_parts = pathinfo($path); if (!is_array($path_parts)) return false; return array_search(strtolower($path_parts['extension']), self::$ImgExts); } /** * Change save path to image type * * @param string $path image path * @param int $imgType image type * @return string new path */ static public function ReplaceExtByImgType($path, $imgType) { if (!array_key_exists($imgType, self::$ImgExts)) return false; $path_parts = pathinfo($path); return $path_parts['dirname'].DIRECTORY_SEPARATOR.$path_parts['filename'].'.'.strtolower(self::$ImgExts[$imgType]); } } |