1
+ <?php
2
+ /*=========================================================================
3
+ MIDAS Server
4
+ Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5
+ 69328 Lyon, FRANCE.
6
+
7
+ See Copyright.txt for details.
8
+ This software is distributed WITHOUT ANY WARRANTY; without even
9
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10
+ PURPOSE. See the above copyright notices for more information.
11
+ =========================================================================*/
12
+
13
+ class Thumbnailcreator_ImagemagickComponent extends AppComponent
14
+ {
15
+ /** createThumbnail */
16
+ public function createThumbnail ($ item )
17
+ {
18
+ $ modelLoader = new MIDAS_ModelLoader ;
19
+ $ itemModel = $ modelLoader ->loadModel ("Item " );
20
+ $ item = $ itemModel ->load ($ item ['item_id ' ]);
21
+ $ revision = $ itemModel ->getLastRevision ($ item );
22
+ $ bitstreams = $ revision ->getBitstreams ();
23
+ if (count ($ bitstreams ) != 1 )
24
+ {
25
+ return ;
26
+ }
27
+ $ bitstream = $ bitstreams [0 ];
28
+ $ ext = strtolower (substr (strrchr ($ bitstream ->getName (), '. ' ), 1 ));
29
+
30
+ // create destination
31
+ $ tmpPath = BASE_PATH .'/data/thumbnail/ ' .rand (1 , 1000 );
32
+ if (!file_exists (BASE_PATH .'/data/thumbnail/ ' ))
33
+ {
34
+ throw new Zend_Exception ("Problem thumbnail path: " .BASE_PATH .'/data/thumbnail/ ' );
35
+ }
36
+ if (!file_exists ($ tmpPath ))
37
+ {
38
+ mkdir ($ tmpPath );
39
+ }
40
+ $ tmpPath .= '/ ' .rand (1 , 1000 );
41
+ if (!file_exists ($ tmpPath ))
42
+ {
43
+ mkdir ($ tmpPath );
44
+ }
45
+ $ destionation = $ tmpPath ."/ " .rand (1 , 1000 ).'.jpeg ' ;
46
+ while (file_exists ($ destionation ))
47
+ {
48
+ $ destionation = $ tmpPath ."/ " .rand (1 , 1000 ).'.jpeg ' ;
49
+ }
50
+ $ pathThumbnail = $ destionation ;
51
+
52
+ require_once BASE_PATH .'/modules/thumbnailcreator/library/Phmagick/phmagick.php ' ;
53
+ $ modulesConfig =Zend_Registry::get ('configsModules ' );
54
+ $ imageMagickPath = $ modulesConfig ['thumbnailcreator ' ]->imagemagick ;
55
+
56
+ // try to create a thumbnail (generic way)
57
+ try
58
+ {
59
+ switch ($ ext )
60
+ {
61
+ case "pdf " :
62
+ case "mpg " :
63
+ case "mpeg " :
64
+ case "mp4 " :
65
+ case "m4v " :
66
+ case "avi " :
67
+ case "mov " :
68
+ case "flv " :
69
+ case "mp4 " :
70
+ case "rm " :
71
+ $ p = new phMagick ("" , $ pathThumbnail );
72
+ $ p ->setImageMagickPath ($ imageMagickPath );
73
+ $ p ->acquireFrame ($ bitstream ->getFullPath (), 0 );
74
+ $ p ->resizeExactly (100 ,100 );
75
+ break ;
76
+ break ;
77
+ default :
78
+ $ p = new phMagick ($ bitstream ->getFullPath (), $ pathThumbnail );
79
+ $ p ->setImageMagickPath ($ imageMagickPath );
80
+ $ p ->resizeExactly (100 ,100 );
81
+ }
82
+ }
83
+ catch (phMagickException $ exc )
84
+ {
85
+ echo $ exc ->getMessage ();
86
+ }
87
+ catch (Exception $ exc )
88
+ {
89
+
90
+ }
91
+
92
+ if (file_exists ($ pathThumbnail ))
93
+ {
94
+ $ oldThumbnail = $ item ->getThumbnail ();
95
+ if (!empty ($ oldThumbnail ))
96
+ {
97
+ unlink ($ oldThumbnail );
98
+ }
99
+ $ item ->setThumbnail (substr ($ pathThumbnail , strlen (BASE_PATH ) + 1 ));
100
+ $ itemModel ->save ($ item );
101
+ }
102
+ return ;
103
+ }
104
+
105
+ } // end class
106
+ ?>
0 commit comments