This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Charles Ma
committed
Jun 27, 2011
1 parent
57494d7
commit f3f5b4d
Showing
29 changed files
with
1,817 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
/*========================================================================= | ||
MIDAS Server | ||
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved. | ||
69328 Lyon, FRANCE. | ||
See Copyright.txt for details. | ||
This software is distributed WITHOUT ANY WARRANTY; without even | ||
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
PURPOSE. See the above copyright notices for more information. | ||
=========================================================================*/ | ||
|
||
|
||
class Thumbnailcreator_AppController extends MIDAS_GlobalModule | ||
{ | ||
public $moduleName='thumbnailcreator'; | ||
} //end class | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** notification manager*/ | ||
class Thumbnailcreator_Notification extends MIDAS_Notification | ||
{ | ||
public $_moduleComponents=array('Imagemagick'); | ||
public $moduleName = 'thumbnailcreator'; | ||
|
||
/** init notification process*/ | ||
public function init() | ||
{ | ||
$this->addTask("TASK_THUMBNAILCREATOR_CREATE", 'createThumbnail', "Create Thumbnail. Parameters: Item, Revision"); | ||
$this->addEvent('EVENT_CORE_CREATE_THUMBNAIL', 'TASK_THUMBNAILCREATOR_CREATE'); | ||
}//end init | ||
|
||
/** createThumbnail */ | ||
public function createThumbnail($params) | ||
{ | ||
$this->ModuleComponent->Imagemagick->createThumbnail($params[0]); | ||
return; | ||
} | ||
} //end class | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.local.ini | ||
*.local.ini.old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[global] | ||
; version of the module | ||
version = 1.0.0 | ||
; full name | ||
fullname= Thumbnail Creator | ||
; description | ||
description= Using Image Magick | ||
;Category | ||
category= Filter | ||
;Dependencies | ||
dependencies= scheduler | ||
|
||
;image magick folder | ||
imagemagick= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/*========================================================================= | ||
MIDAS Server | ||
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved. | ||
69328 Lyon, FRANCE. | ||
See Copyright.txt for details. | ||
This software is distributed WITHOUT ANY WARRANTY; without even | ||
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
PURPOSE. See the above copyright notices for more information. | ||
=========================================================================*/ | ||
|
||
//define("MIDAS_EXAMPLE", 0); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/*========================================================================= | ||
MIDAS Server | ||
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved. | ||
69328 Lyon, FRANCE. | ||
See Copyright.txt for details. | ||
This software is distributed WITHOUT ANY WARRANTY; without even | ||
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
PURPOSE. See the above copyright notices for more information. | ||
=========================================================================*/ | ||
|
||
|
||
class Thumbnailcreator_ConfigController extends Thumbnailcreator_AppController | ||
{ | ||
public $_moduleForms=array('Config'); | ||
public $_components=array('Utility', 'Date'); | ||
|
||
/** index action*/ | ||
function indexAction() | ||
{ | ||
if(!$this->logged||!$this->userSession->Dao->getAdmin()==1) | ||
{ | ||
throw new Zend_Exception("You should be an administrator"); | ||
} | ||
|
||
if(file_exists(BASE_PATH."/core/configs/".$this->moduleName.".local.ini")) | ||
{ | ||
$applicationConfig = parse_ini_file(BASE_PATH."/core/configs/".$this->moduleName.".local.ini", true); | ||
} | ||
else | ||
{ | ||
$applicationConfig = parse_ini_file(BASE_PATH.'/modules/'.$this->moduleName.'/configs/module.ini', true); | ||
} | ||
$configForm = $this->ModuleForm->Config->createConfigForm(); | ||
|
||
$formArray = $this->getFormAsArray($configForm); | ||
$formArray['imagemagick']->setValue($applicationConfig['global']['imagemagick']); | ||
|
||
$this->view->configForm = $formArray; | ||
|
||
if($this->_request->isPost()) | ||
{ | ||
$this->_helper->layout->disableLayout(); | ||
$this->_helper->viewRenderer->setNoRender(); | ||
$submitConfig = $this->_getParam('submitConfig'); | ||
if(isset($submitConfig)) | ||
{ | ||
if(file_exists(BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old")) | ||
{ | ||
unlink(BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old"); | ||
} | ||
if(file_exists(BASE_PATH."/core/configs/".$this->moduleName.".local.ini")) | ||
{ | ||
rename(BASE_PATH."/core/configs/".$this->moduleName.".local.ini",BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old"); | ||
} | ||
$applicationConfig['global']['imagemagick'] = $this->_getParam('imagemagick'); | ||
$this->Component->Utility->createInitFile(BASE_PATH."/core/configs/".$this->moduleName.".local.ini", $applicationConfig); | ||
echo JsonComponent::encode(array(true, 'Changed saved')); | ||
} | ||
} | ||
} | ||
|
||
}//end class |
106 changes: 106 additions & 0 deletions
106
modules/thumbnailcreator/controllers/components/ImagemagickComponent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
/*========================================================================= | ||
MIDAS Server | ||
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved. | ||
69328 Lyon, FRANCE. | ||
See Copyright.txt for details. | ||
This software is distributed WITHOUT ANY WARRANTY; without even | ||
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
PURPOSE. See the above copyright notices for more information. | ||
=========================================================================*/ | ||
|
||
class Thumbnailcreator_ImagemagickComponent extends AppComponent | ||
{ | ||
/** createThumbnail */ | ||
public function createThumbnail($item) | ||
{ | ||
$modelLoader = new MIDAS_ModelLoader; | ||
$itemModel = $modelLoader->loadModel("Item"); | ||
$item = $itemModel->load($item['item_id']); | ||
$revision = $itemModel->getLastRevision($item); | ||
$bitstreams = $revision->getBitstreams(); | ||
if(count($bitstreams) != 1) | ||
{ | ||
return; | ||
} | ||
$bitstream = $bitstreams[0]; | ||
$ext = strtolower(substr(strrchr($bitstream->getName(), '.'), 1)); | ||
|
||
// create destination | ||
$tmpPath = BASE_PATH.'/data/thumbnail/'.rand(1, 1000); | ||
if(!file_exists(BASE_PATH.'/data/thumbnail/')) | ||
{ | ||
throw new Zend_Exception("Problem thumbnail path: ".BASE_PATH.'/data/thumbnail/'); | ||
} | ||
if(!file_exists($tmpPath)) | ||
{ | ||
mkdir($tmpPath); | ||
} | ||
$tmpPath .= '/'.rand(1, 1000); | ||
if(!file_exists($tmpPath)) | ||
{ | ||
mkdir($tmpPath); | ||
} | ||
$destionation = $tmpPath."/".rand(1, 1000).'.jpeg'; | ||
while(file_exists($destionation)) | ||
{ | ||
$destionation = $tmpPath."/".rand(1, 1000).'.jpeg'; | ||
} | ||
$pathThumbnail = $destionation; | ||
|
||
require_once BASE_PATH.'/modules/thumbnailcreator/library/Phmagick/phmagick.php'; | ||
$modulesConfig=Zend_Registry::get('configsModules'); | ||
$imageMagickPath = $modulesConfig['thumbnailcreator']->imagemagick; | ||
|
||
// try to create a thumbnail (generic way) | ||
try | ||
{ | ||
switch($ext) | ||
{ | ||
case "pdf": | ||
case "mpg": | ||
case "mpeg": | ||
case "mp4": | ||
case "m4v": | ||
case "avi": | ||
case "mov": | ||
case "flv": | ||
case "mp4": | ||
case "rm": | ||
$p = new phMagick("", $pathThumbnail); | ||
$p->setImageMagickPath($imageMagickPath); | ||
$p->acquireFrame($bitstream->getFullPath(), 0); | ||
$p->resizeExactly(100,100); | ||
break; | ||
break; | ||
default: | ||
$p = new phMagick($bitstream->getFullPath(), $pathThumbnail); | ||
$p->setImageMagickPath($imageMagickPath); | ||
$p->resizeExactly(100,100); | ||
} | ||
} | ||
catch (phMagickException $exc) | ||
{ | ||
echo $exc->getMessage(); | ||
} | ||
catch (Exception $exc) | ||
{ | ||
|
||
} | ||
|
||
if(file_exists($pathThumbnail)) | ||
{ | ||
$oldThumbnail = $item->getThumbnail(); | ||
if(!empty($oldThumbnail)) | ||
{ | ||
unlink($oldThumbnail); | ||
} | ||
$item->setThumbnail(substr($pathThumbnail, strlen(BASE_PATH) + 1)); | ||
$itemModel->save($item); | ||
} | ||
return; | ||
} | ||
|
||
} // end class | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/*========================================================================= | ||
MIDAS Server | ||
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved. | ||
69328 Lyon, FRANCE. | ||
See Copyright.txt for details. | ||
This software is distributed WITHOUT ANY WARRANTY; without even | ||
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
PURPOSE. See the above copyright notices for more information. | ||
=========================================================================*/ | ||
|
||
class Thumbnailcreator_ConfigForm extends AppForm | ||
{ | ||
|
||
/** create form */ | ||
public function createConfigForm() | ||
{ | ||
$form = new Zend_Form; | ||
|
||
$form->setAction($this->webroot.'/thumbnailcreator/config/index') | ||
->setMethod('post'); | ||
|
||
$imagemagick = new Zend_Form_Element_Text('imagemagick'); | ||
|
||
$submit = new Zend_Form_Element_Submit('submitConfig'); | ||
$submit ->setLabel('Save configuration'); | ||
|
||
$form->addElements(array($imagemagick, $submit)); | ||
return $form; | ||
} | ||
|
||
} // end class | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Thank you for downloading phMagick | ||
|
||
phMagick needs 2 things to be sucessfully installed | ||
|
||
* imagemagick available ate http://www.imagemagick.org | ||
* and php must allow access to the exec() function. | ||
|
||
For examples you can browse http://www.francodacosta.com/phmagick there are pleanty of examples there. | ||
|
||
|
||
Basic Mechanics | ||
|
||
phMagick philosophy is extremely simple, you say where is the source image and where you want the new image and then apply actions to it | ||
One great feature of phMagick is that you can apply several actions to an image, making it extremely powerful and able to create very complex images | ||
|
||
In the combination example below you will see how easy it is to create a thumbnail with rounded corners and then applying a drop shadow to it. | ||
|
||
Enough talking, let's look at some example code to see its simplicity | ||
|
||
<?php | ||
include "phMagick.php"; | ||
$p = new phMagick("source.png","destination.png"); | ||
$p->rotate(45); | ||
?> | ||
|
||
In the first line we tell PHP that we are using a file named phMagick.php, it's were phMagick is declared, you only need to do this once. | ||
Line 2 creates a phMagick instance, and say that source.png will be our source image and destination.png will be the new image | ||
Line 3 does the magic, in this case rotates source.png 45 degrees and saves it as destination.png | ||
|
||
|
||
If you need assistance feel free to mail me at sven @ francodacosta.com . |
Oops, something went wrong.