1<?php 2/* 3 * Gallery - a web based photo album viewer and editor 4 * Copyright (C) 2000-2008 Bharat Mediratta 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or (at 9 * your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, but 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 19 */ 20 21/** 22 * This ItemAddOption adds a watermark on movie thumbnails. 23 * @package Ffmpeg 24 * @subpackage UserInterface 25 * @author Alan Harder <alan.harder@sun.com> 26 * @version $Revision: 17580 $ 27 */ 28class MovieThumbnailOption extends ItemAddOption { 29 30 /** 31 * @see ItemAddOption::isAppropriate 32 */ 33 function isAppropriate() { 34 list ($ret, $useWatermark) = 35 GalleryCoreApi::getPluginParameter('module', 'ffmpeg', 'useWatermark'); 36 if ($ret) { 37 return array($ret, null); 38 } 39 list ($ret, $toolkit) = GalleryCoreApi::getToolkitByOperation('image/jpeg', 'composite'); 40 if ($ret) { 41 return array($ret, null); 42 } 43 return array(null, $useWatermark && isset($toolkit)); 44 } 45 46 /** 47 * @see ItemAddOption::handleRequestAfterAdd 48 */ 49 function handleRequestAfterAdd($form, $items) { 50 $errors = $warnings = $movieIds = $thumbIds = array(); 51 foreach ($items as $item) { 52 if (GalleryUtilities::isA($item, 'GalleryMovieItem')) { 53 $movieIds[] = $item->getId(); 54 } 55 } 56 if (!empty($movieIds)) { 57 list ($ret, $thumbTable) = GalleryCoreApi::fetchThumbnailsByItemIds($movieIds); 58 if ($ret) { 59 return array($ret, null, null); 60 } 61 foreach ($thumbTable as $itemId => $thumbnail) { 62 $thumbIds[] = $thumbnail->getId(); 63 } 64 } 65 if (empty($thumbIds)) { 66 return array(null, $errors, $warnings); 67 } 68 list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($thumbIds); 69 if ($ret) { 70 return array($ret, null, null); 71 } 72 73 $op = 'composite|plugins_data/modules/ffmpeg/filmreel.png,image/png,12,399'; 74 foreach ($thumbTable as $itemId => $thumbnail) { 75 list ($ret, $thumbnail) = $thumbnail->refresh(); 76 if ($ret) { 77 GalleryCoreApi::releaseLocks($lockId); 78 return array($ret, null, null); 79 } 80 81 /* 82 * Set operations not postFilter so if this item is selected as an album highlight 83 * then the highlight will get the watermark too. 84 */ 85 $operations = $thumbnail->getDerivativeOperations(); 86 $operations .= (empty($operations) ? '' : ';') . "$op,top-left,0,0;$op,top-right,0,0"; 87 $thumbnail->setDerivativeOperations($operations); 88 89 $ret = $thumbnail->save(); 90 if ($ret) { 91 GalleryCoreApi::releaseLocks($lockId); 92 return array($ret, null, null); 93 } 94 } 95 96 $ret = GalleryCoreApi::releaseLocks($lockId); 97 if ($ret) { 98 return array($ret, null, null); 99 } 100 101 return array(null, $errors, $warnings); 102 } 103} 104?> 105