Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit b98337d

Browse files
author
Charles Marion
committed
0009693: ItemrevisionBase create thumbnail
1 parent a0d9566 commit b98337d

File tree

2 files changed

+138
-136
lines changed

2 files changed

+138
-136
lines changed

core/models/base/ItemRevisionModelBase.php

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,144 @@ public function __construct()
4141

4242
abstract function getByUuid($uuid);
4343
abstract function getMetadata($revisiondao);
44+
45+
/** Add a bitstream to a revision */
46+
function addBitstream($itemRevisionDao, $bitstreamDao)
47+
{
48+
$modelLoad = new MIDAS_ModelLoader();
49+
$BitstreamModel = $modelLoad->loadModel('Bitstream');
50+
$ItemModel = $modelLoad->loadModel('Item');
51+
// $TaskModel = $modelLoad->loadModel('Task');
52+
53+
$bitstreamDao->setItemrevisionId($itemRevisionDao->getItemrevisionId());
54+
55+
// Save the bistream
56+
$bitstreamDao->setDate(date('c'));
57+
$BitstreamModel->save($bitstreamDao);
58+
59+
$item = $itemRevisionDao->getItem($bitstreamDao);
60+
$item->setSizebytes($this->getSize($itemRevisionDao));
61+
$item->setDate(date('c'));
62+
63+
$modulesThumbnail = Zend_Registry::get('notifier')->notify(MIDAS_NOTIFY_CREATE_THUMBNAIL);
64+
if(empty($modulesThumbnail))
65+
{
66+
$mime = $bitstreamDao->getMimetype();
67+
$tmpfile = $bitstreamDao->getPath();
68+
if(!file_exists($tmpfile))
69+
{
70+
$tmpfile = $bitstreamDao->getFullPath();
71+
}
72+
// Creating temp image as a source image (original image).
73+
$createThumb = true;
74+
if(file_exists($tmpfile) && $mime == 'image/jpeg')
75+
{
76+
try
77+
{
78+
$src = imagecreatefromjpeg($tmpfile);
79+
}
80+
catch (Exception $exc)
81+
{
82+
$createThumb = false;
83+
}
84+
}
85+
else if(file_exists($tmpfile) && $mime == 'image/png')
86+
{
87+
try
88+
{
89+
$src = imagecreatefrompng($tmpfile);
90+
}
91+
catch (Exception $exc)
92+
{
93+
$createThumb = false;
94+
}
95+
}
96+
else if(file_exists($tmpfile) && $mime == 'image/gif')
97+
{
98+
try
99+
{
100+
$src = imagecreatefromgif($tmpfile);
101+
}
102+
catch (Exception $exc)
103+
{
104+
$createThumb = false;
105+
}
106+
}
107+
else
108+
{
109+
$createThumb = false;
110+
}
111+
112+
if($createThumb)
113+
{
114+
$tmpPath = BASE_PATH.'/data/thumbnail/'.rand(1, 1000);
115+
if(!file_exists(BASE_PATH.'/data/thumbnail/'))
116+
{
117+
throw new Zend_Exception("Problem thumbnail path: ".BASE_PATH.'/data/thumbnail/');
118+
}
119+
if(!file_exists($tmpPath))
120+
{
121+
mkdir($tmpPath);
122+
}
123+
$tmpPath .= '/'.rand(1, 1000);
124+
if(!file_exists($tmpPath))
125+
{
126+
mkdir($tmpPath);
127+
}
128+
$destionation = $tmpPath."/".rand(1, 1000).'.jpeg';
129+
while(file_exists($destionation))
130+
{
131+
$destionation = $tmpPath."/".rand(1, 1000).'.jpeg';
132+
}
133+
$pathThumbnail=$destionation;
134+
135+
list ($x, $y) = @getimagesize ($tmpfile); //--- get size of img ---
136+
$thumb = 100; //--- max. size of thumb ---
137+
if($x > $y)
138+
{
139+
$tx = $thumb; //--- landscape ---
140+
$ty = round($thumb / $x * $y);
141+
}
142+
else
143+
{
144+
$tx = round($thumb / $y * $x); //--- portrait ---
145+
$ty = $thumb;
146+
}
147+
148+
$thb = imagecreatetruecolor ($tx, $ty); //--- create thumbnail ---
149+
imagecopyresampled ($thb,$src, 0,0, 0,0, $tx,$ty, $x,$y);
150+
imagejpeg ($thb, $pathThumbnail, 80);
151+
imagedestroy ($thb);
152+
imagedestroy ($src);
153+
}
154+
}
155+
else
156+
{
157+
$createThumb = false;
158+
//TODO
159+
/*
160+
require_once BASE_PATH.'/core/controllers/components/FilterComponent.php';
161+
$filterComponent = new FilterComponent();
162+
$thumbnailCreator = $filterComponent->getFilter('ThumbnailCreator');
163+
$thumbnailCreator->inputFile = $bitstreamDao->getFullPath();
164+
$thumbnailCreator->inputName = $bitstreamDao->getName();
165+
$hasThumbnail = $thumbnailCreator->process();
166+
167+
*/
168+
}
169+
170+
if($createThumb)
171+
{
172+
$oldThumbnail = $item->getThumbnail();
173+
if(!empty($oldThumbnail))
174+
{
175+
unlink($oldThumbnail);
176+
}
177+
$item->setThumbnail(substr($pathThumbnail, strlen(BASE_PATH)+1));
178+
}
179+
$ItemModel->save($item);
180+
} // end addBitstream
181+
44182

45183
/** save */
46184
public function save($dao)

core/models/pdo/ItemRevisionModel.php

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -116,142 +116,6 @@ function getBitstreamByName($revision, $name)
116116
return $this->initDao('Bitstream', $row);
117117
} // end getBitstreamByName
118118

119-
/** Add a bitstream to a revision */
120-
function addBitstream($itemRevisionDao, $bitstreamDao)
121-
{
122-
$modelLoad = new MIDAS_ModelLoader();
123-
$BitstreamModel = $modelLoad->loadModel('Bitstream');
124-
$ItemModel = $modelLoad->loadModel('Item');
125-
// $TaskModel = $modelLoad->loadModel('Task');
126-
127-
$bitstreamDao->setItemrevisionId($itemRevisionDao->getItemrevisionId());
128-
129-
// Save the bistream
130-
$bitstreamDao->setDate(date('c'));
131-
$BitstreamModel->save($bitstreamDao);
132-
133-
$item = $itemRevisionDao->getItem($bitstreamDao);
134-
$item->setSizebytes($this->getSize($itemRevisionDao));
135-
$item->setDate(date('c'));
136119

137-
$modulesThumbnail = Zend_Registry::get('notifier')->notify(MIDAS_NOTIFY_CREATE_THUMBNAIL);
138-
if(empty($modulesThumbnail))
139-
{
140-
$mime = $bitstreamDao->getMimetype();
141-
$tmpfile = $bitstreamDao->getPath();
142-
if(!file_exists($tmpfile))
143-
{
144-
$tmpfile = $bitstreamDao->getFullPath();
145-
}
146-
// Creating temp image as a source image (original image).
147-
$createThumb = true;
148-
if(file_exists($tmpfile) && $mime == 'image/jpeg')
149-
{
150-
try
151-
{
152-
$src = imagecreatefromjpeg($tmpfile);
153-
}
154-
catch (Exception $exc)
155-
{
156-
$createThumb = false;
157-
}
158-
}
159-
else if(file_exists($tmpfile) && $mime == 'image/png')
160-
{
161-
try
162-
{
163-
$src = imagecreatefrompng($tmpfile);
164-
}
165-
catch (Exception $exc)
166-
{
167-
$createThumb = false;
168-
}
169-
}
170-
else if(file_exists($tmpfile) && $mime == 'image/gif')
171-
{
172-
try
173-
{
174-
$src = imagecreatefromgif($tmpfile);
175-
}
176-
catch (Exception $exc)
177-
{
178-
$createThumb = false;
179-
}
180-
}
181-
else
182-
{
183-
$createThumb = false;
184-
}
185-
186-
if($createThumb)
187-
{
188-
$tmpPath = BASE_PATH.'/data/thumbnail/'.rand(1, 1000);
189-
if(!file_exists(BASE_PATH.'/data/thumbnail/'))
190-
{
191-
throw new Zend_Exception("Problem thumbnail path: ".BASE_PATH.'/data/thumbnail/');
192-
}
193-
if(!file_exists($tmpPath))
194-
{
195-
mkdir($tmpPath);
196-
}
197-
$tmpPath .= '/'.rand(1, 1000);
198-
if(!file_exists($tmpPath))
199-
{
200-
mkdir($tmpPath);
201-
}
202-
$destionation = $tmpPath."/".rand(1, 1000).'.jpeg';
203-
while(file_exists($destionation))
204-
{
205-
$destionation = $tmpPath."/".rand(1, 1000).'.jpeg';
206-
}
207-
$pathThumbnail=$destionation;
208-
209-
list ($x, $y) = @getimagesize ($tmpfile); //--- get size of img ---
210-
$thumb = 100; //--- max. size of thumb ---
211-
if($x > $y)
212-
{
213-
$tx = $thumb; //--- landscape ---
214-
$ty = round($thumb / $x * $y);
215-
}
216-
else
217-
{
218-
$tx = round($thumb / $y * $x); //--- portrait ---
219-
$ty = $thumb;
220-
}
221-
222-
$thb = imagecreatetruecolor ($tx, $ty); //--- create thumbnail ---
223-
imagecopyresampled ($thb,$src, 0,0, 0,0, $tx,$ty, $x,$y);
224-
imagejpeg ($thb, $pathThumbnail, 80);
225-
imagedestroy ($thb);
226-
imagedestroy ($src);
227-
}
228-
}
229-
else
230-
{
231-
$createThumb = false;
232-
//TODO
233-
/*
234-
require_once BASE_PATH.'/core/controllers/components/FilterComponent.php';
235-
$filterComponent = new FilterComponent();
236-
$thumbnailCreator = $filterComponent->getFilter('ThumbnailCreator');
237-
$thumbnailCreator->inputFile = $bitstreamDao->getFullPath();
238-
$thumbnailCreator->inputName = $bitstreamDao->getName();
239-
$hasThumbnail = $thumbnailCreator->process();
240-
241-
*/
242-
}
243-
244-
if($createThumb)
245-
{
246-
$oldThumbnail = $item->getThumbnail();
247-
if(!empty($oldThumbnail))
248-
{
249-
unlink($oldThumbnail);
250-
}
251-
$item->setThumbnail(substr($pathThumbnail, strlen(BASE_PATH)+1));
252-
}
253-
$ItemModel->save($item);
254-
} // end addBitstream
255-
256120
} // end class
257121
?>

0 commit comments

Comments
 (0)