[24676] | 1 | <?php |
---|
| 2 | /*********************************************** |
---|
| 3 | * File : function_frame.php |
---|
| 4 | * Project : piwigo-videojs |
---|
| 5 | * Descr : Generate the thumbnail with frame |
---|
| 6 | * Base on : Embedded Videos plugin |
---|
| 7 | * |
---|
| 8 | * Created : 21.06.2013 |
---|
| 9 | * |
---|
| 10 | * Copyright 2012-2013 <xbgmsharp@gmail.com> |
---|
| 11 | * |
---|
| 12 | * |
---|
| 13 | * This program is free software: you can redistribute it and/or modify |
---|
| 14 | * it under the terms of the GNU General Public License as published by |
---|
| 15 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 16 | * (at your option) any later version. |
---|
| 17 | * |
---|
| 18 | * This program is distributed in the hope that it will be useful, |
---|
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 21 | * GNU General Public License for more details. |
---|
| 22 | * |
---|
| 23 | * You should have received a copy of the GNU General Public License |
---|
| 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 25 | * |
---|
| 26 | ************************************************/ |
---|
| 27 | |
---|
| 28 | // Check whether we are indeed included by Piwigo. |
---|
| 29 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * add movie frame to an image (need GD library) |
---|
| 33 | * @param: string source |
---|
| 34 | * @param: string destination (if null, the source is modified) |
---|
| 35 | * @return: void |
---|
| 36 | */ |
---|
| 37 | function add_movie_frame($src, $dest=null) |
---|
| 38 | { |
---|
| 39 | if (empty($dest)) |
---|
| 40 | { |
---|
| 41 | $dest = $src; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | // we need gd library |
---|
| 45 | if (!function_exists('imagecreatetruecolor')) |
---|
| 46 | { |
---|
| 47 | if ($dest != $src) copy($src, $dest); |
---|
| 48 | return; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | // open source image |
---|
| 52 | switch (strtolower(get_extension($src))) |
---|
| 53 | { |
---|
| 54 | case 'jpg': |
---|
| 55 | case 'jpeg': |
---|
| 56 | $srcImage = imagecreatefromjpeg($src); |
---|
| 57 | break; |
---|
| 58 | case 'png': |
---|
| 59 | $srcImage = imagecreatefrompng($src); |
---|
| 60 | break; |
---|
| 61 | case 'gif': |
---|
| 62 | $srcImage = imagecreatefromgif($src); |
---|
| 63 | break; |
---|
| 64 | default: |
---|
| 65 | if ($dest != $src) copy($src, $dest); |
---|
| 66 | return; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | // source properties |
---|
| 70 | $srcWidth = imagesx($srcImage); |
---|
| 71 | $srcHeight = imagesy($srcImage); |
---|
| 72 | $const = intval($srcWidth * 0.04); |
---|
| 73 | $bandRadius = floor($const/8); |
---|
| 74 | |
---|
| 75 | // band properties |
---|
| 76 | $imgBand = imagecreatetruecolor($srcWidth + 6*$const, $srcHeight + 3*$const); |
---|
| 77 | |
---|
| 78 | $black = imagecolorallocate($imgBand, 0, 0, 0); |
---|
| 79 | $white = imagecolorallocate($imgBand, 245, 245, 245); |
---|
| 80 | |
---|
| 81 | // and dots |
---|
| 82 | $y_start = intval(($srcHeight + 3*$const) / 2); |
---|
| 83 | $aug = intval($y_start / 5) + 1; |
---|
| 84 | $i = 0; |
---|
| 85 | |
---|
| 86 | while ($y_start + $i*$aug < $srcHeight + 3*$const) |
---|
| 87 | { |
---|
| 88 | imagefilledroundrectangle($imgBand, (3/4)*$const, $y_start + $i*$aug - $const/2, (9/4)*$const - 1, $y_start + $i*$aug + $const/2 - 1, $white, $bandRadius); |
---|
| 89 | imagefilledroundrectangle($imgBand, (3/4)*$const, $y_start - $i*$aug - $const/2, (9/4)*$const - 1, $y_start - $i*$aug + $const/2 - 1, $white, $bandRadius); |
---|
| 90 | |
---|
| 91 | 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); |
---|
| 92 | 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); |
---|
| 93 | |
---|
| 94 | ++$i; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | // add source to band |
---|
| 98 | imagecopy($imgBand, $srcImage, 3*$const, (3/2)*$const, 0, 0, $srcWidth, $srcHeight); |
---|
| 99 | |
---|
| 100 | // save image |
---|
| 101 | switch (strtolower(get_extension($dest))) |
---|
| 102 | { |
---|
| 103 | case 'jpg': |
---|
| 104 | case 'jpeg': |
---|
| 105 | imagejpeg($imgBand, $dest, 85); |
---|
| 106 | break; |
---|
| 107 | case 'png': |
---|
| 108 | imagepng($imgBand, $dest); |
---|
| 109 | break; |
---|
| 110 | case 'gif': |
---|
| 111 | imagegif($imgBand, $dest); |
---|
| 112 | break; |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | /** |
---|
| 117 | * create a rectangle with round corners |
---|
| 118 | * http://www.php.net/manual/fr/function.imagefilledrectangle.php#42815 |
---|
| 119 | */ |
---|
| 120 | function imagefilledroundrectangle(&$img, $x1, $y1, $x2, $y2, $color, $radius) |
---|
| 121 | { |
---|
| 122 | imagefilledrectangle($img, $x1+$radius, $y1, $x2-$radius, $y2, $color); |
---|
| 123 | |
---|
| 124 | if ($radius > 0) |
---|
| 125 | { |
---|
| 126 | imagefilledrectangle($img, $x1, $y1+$radius, $x2, $y2-$radius, $color); |
---|
| 127 | imagefilledellipse($img, $x1+$radius, $y1+$radius, $radius*2, $radius*2, $color); |
---|
| 128 | imagefilledellipse($img, $x2-$radius, $y1+$radius, $radius*2, $radius*2, $color); |
---|
| 129 | imagefilledellipse($img, $x1+$radius, $y2-$radius, $radius*2, $radius*2, $color); |
---|
| 130 | imagefilledellipse($img, $x2-$radius, $y2-$radius, $radius*2, $radius*2, $color); |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | ?> |
---|