/extremedating/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/extremedating/trunk

« back to all changes in this revision

Viewing changes to php/stupid_image.php

  • Committer: Gustav Hartvigsson
  • Date: 2013-04-15 16:46:05 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20130415164605-wnyjleu697qa5fc7
Made the uploaded files take less space in the databas, though the use of
a stupid scaling and croping algorithem.
Old files images stored in the database are cropped and farmated when outputed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
*/
 
20
function stupid_rescale_and_crop (Imagick $image, $Height, $Width) {
 
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
  }
 
30
  $image->cropImage(280,280,0,0);
 
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
?>