Changeset 17310 for extensions/gvideo/include/functions.inc.php
- Timestamp:
- Aug 2, 2012, 4:30:30 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/gvideo/include/functions.inc.php
r17307 r17310 289 289 } 290 290 291 /** 292 * and film frame to an image (need GD library) 293 * @param: string source 294 * @param: string destination (if null, the source si modified) 295 * @return: void 296 */ 297 function add_film_frame($src, $dest=null) 298 { 299 if (empty($dest)) 300 { 301 $dest = $src; 302 } 303 304 // we need gd library 305 if (!function_exists('imagecreatetruecolor')) 306 { 307 if ($dest != $src) copy($src, $dest); 308 return; 309 } 310 311 // open source image 312 $imgExt = strtolower(get_extension($src)); 313 switch ($imgExt) 314 { 315 case 'jpg': 316 case 'jpeg': 317 $srcImage = imagecreatefromjpeg($src); 318 break; 319 case 'png': 320 $srcImage = imagecreatefrompng($src); 321 break; 322 case 'gif': 323 $srcImage = imagecreatefromgif($src); 324 break; 325 default: 326 if ($dest != $src) copy($src, $dest); 327 return; 328 } 329 330 // source properties 331 $srcWidth = imagesx($srcImage); 332 $srcHeight = imagesy($srcImage); 333 $const = intval($srcWidth * 0.04); 334 $bandRadius = floor($const/8); 335 336 // band properties 337 $imgBand = imagecreatetruecolor($srcWidth + 6*$const, $srcHeight + 3*$const); 338 339 $black = imagecolorallocate($imgBand, 0, 0, 0); 340 $white = imagecolorallocate($imgBand, 245, 245, 245); 341 342 // and dots 343 $y_start = intval(($srcHeight + 3*$const) / 2); 344 $aug = intval($y_start / 5) + 1; 345 $i = 0; 346 347 while ($y_start + $i*$aug < $srcHeight + 3*$const) 348 { 349 imagefilledroundrectangle($imgBand, (3/4)*$const, $y_start + $i*$aug - $const/2, (9/4)*$const - 1, $y_start + $i*$aug + $const/2 - 1, $white, $bandRadius); 350 imagefilledroundrectangle($imgBand, (3/4)*$const, $y_start - $i*$aug - $const/2, (9/4)*$const - 1, $y_start - $i*$aug + $const/2 - 1, $white, $bandRadius); 351 352 imagefilledroundrectangle($imgBand, $srcWidth + (15/4)*$const, $y_start + $i*$aug - $const/2, $srcWidth + (21/4)*$const - 1, $y_start + $i*$aug + $const/2 - 1, $white, $bandRadius); 353 imagefilledroundrectangle($imgBand, $srcWidth + (15/4)*$const, $y_start - $i*$aug - $const/2, $srcWidth + (21/4)*$const - 1, $y_start - $i*$aug + $const/2 - 1, $white, $bandRadius); 354 355 ++$i; 356 } 357 358 // add source to band 359 imagecopy($imgBand, $srcImage, 3*$const, (3/2)*$const, 0, 0, $srcWidth, $srcHeight); 360 361 // save image 362 switch ($imgExt) 363 { 364 case 'jpg': 365 case 'jpeg': 366 imagejpeg($imgBand, $dest); 367 break; 368 case 'png': 369 imagepng($imgBand, $dest); 370 break; 371 case 'gif': 372 imagegif($imgBand, $dest); 373 break; 374 } 375 } 376 377 /** 378 * create a rectangle with round corners 379 * http://www.php.net/manual/fr/function.imagefilledrectangle.php#42815 380 */ 381 function imagefilledroundrectangle(&$img, $x1, $y1, $x2, $y2, $color, $radius) 382 { 383 imagefilledrectangle($img, $x1+$radius, $y1, $x2-$radius, $y2, $color); 384 385 if ($radius > 0) 386 { 387 imagefilledrectangle($img, $x1, $y1+$radius, $x2, $y2-$radius, $color); 388 imagefilledellipse($img, $x1+$radius, $y1+$radius, $radius*2, $radius*2, $color); 389 imagefilledellipse($img, $x2-$radius, $y1+$radius, $radius*2, $radius*2, $color); 390 imagefilledellipse($img, $x1+$radius, $y2-$radius, $radius*2, $radius*2, $color); 391 imagefilledellipse($img, $x2-$radius, $y2-$radius, $radius*2, $radius*2, $color); 392 } 393 } 394 291 395 ?>
Note: See TracChangeset
for help on using the changeset viewer.