/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 get_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:
19
19
 
20
20
    You should have received a copy of the GNU Affero General Public License
21
21
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
    --------------------------------------------------------------------------
 
23
 
 
24
    This file, as a standalone file is also avalible under GNU Lesser General
 
25
    Public License either version 3 of the License, or (at your option) any
 
26
    later version.
 
27
 
22
28
*/
23
29
include "php/db.php";
 
30
include "php/stupid_image.php";
24
31
 
25
32
$def =
26
33
"iVBORw0KGgoAAAANSUhEUgAAARgAAAEYCAYAAACHjumMAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
181
188
Y4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOM
182
189
McYYY4wxxhhjjDFj8v+EX5l2R3A63QAAAABJRU5ErkJggg==";
183
190
 
 
191
 
184
192
header("Content-type: image/png");
185
193
if(isset($_GET['userName']) ){
186
194
  $username = $_GET['userName'];
190
198
  $fetch = $tuples->fetchAll();
191
199
  //var_dump($fetch);
192
200
  if(count($fetch) > 0 && $fetch[0]['profileImage'] != "" ) {
193
 
    echo(base64_decode($fetch[0]['profileImage']));
 
201
    $image = new Imagick();
 
202
    $image->readImageBlob(base64_decode($fetch[0]['profileImage']));
 
203
    $imageprops = $image->getImageGeometry();
 
204
    /*var_dump($imageprops);
 
205
    if ($imageprops['height'] > 280 || $imageprops['width'] > 280){
 
206
      $image->resizeImage(280,280);
 
207
    } else if ($imageprops['height'] < 280 || $imageprops['width'] < 280) {
 
208
      if ($imageprops['height'] = $imageprops['width'] ) {
 
209
        $image->resizeImage(280,280, imagick::FILTER_LANCZOS, 0, false);
 
210
      } else if ($imageprops['height'] > $imageprops['width'] ){
 
211
        $image->resizeImage(280,0, imagick::FILTER_LANCZOS, 0, false);
 
212
      } else if ($imageprops['height'] < $imageprops['width'] ){
 
213
        $image->resizeImage(0, 280, imagick::FILTER_LANCZOS, 0, false);
 
214
      }
 
215
      $image->cropImage(280,280,0,0);
 
216
    }
 
217
    */
 
218
    //var_dump($image);
 
219
    $img = stupid_rescale_and_crop($image, 280, 280);
 
220
    $img->setImageFormat("png");
 
221
    echo($img);
194
222
  } else {
195
223
    echo base64_decode($def);
196
224
  }