/extremedating/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/extremedating/trunk
68 by Gustav Hartvigsson
Made the uploaded files take less space in the databas, though the use of
1
<?php
2
/*
3
    Stupid Image Utils - part of 
4
    ExtremeDating - a Hackathon 2013 project.
5
    Copyright (C) 2013 Gustav Hartvigsson <gustav.hartvigsson@gmail.com>
6
7
    This program is free software: you can redistribute it and/or modify
8
    it under the terms of the GNU Lesser General Public License as
9
    published by the Free Software Foundation, either version 3 of the
10
    License, or (at your option) any later version.
11
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU Affero General Public License for more details.
16
17
    You should have received a copy of the GNU Lesser General Public License
18
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
*/
69 by Gustav Hartvigsson
Added offset to the stupid rescale and crop function and fixed a bug.
20
function stupid_rescale_and_crop (Imagick $image, $Height, $Width, $offsetX = 0, $offsetY = 0) {
68 by Gustav Hartvigsson
Made the uploaded files take less space in the databas, though the use of
21
  //var_dump($image);
22
  $imageprops = $image->getImageGeometry();
23
  if ($imageprops['height'] == $imageprops['width'] ) {
24
    $image->resizeImage($Height, $Width, imagick::FILTER_LANCZOS, true, false);
25
  } elseif ($imageprops['height'] > $imageprops['width'] ){
26
    $image->resizeImage($Height,0 , imagick::FILTER_LANCZOS, true, false);
27
  } elseif ($imageprops['height'] < $imageprops['width'] ){
28
    $image->resizeImage(0, $Width, imagick::FILTER_LANCZOS, true, false);
29
  }
69 by Gustav Hartvigsson
Added offset to the stupid rescale and crop function and fixed a bug.
30
  $image->cropImage($Height, $Width, $offsetX, $offsetY);
68 by Gustav Hartvigsson
Made the uploaded files take less space in the databas, though the use of
31
32
  return $image;
33
}
34
35
function stupid_convert_and_rescale (Imagick $image, $Height, $Width, $format ) {
36
  $image = stupid_rescale_and_crop($image, $Height, $Width);
37
  $image->setFormat($format);
38
  return $image;
39
}
40
?>