Show
Ignore:
Timestamp:
05/17/07 16:25:43 (5 years ago)
Author:
fproulx
Message:

2007-05-17 François Proulx <francois.proulx@…>

  • WARNING: This has not been fully tested. Full testing to be completed on 2006-05-18 but I'm pretty confident that it works pretty well.
  • Added automatic resize on Avatars
  • Added FavoriteHotspots? content (mostly used for Profiles)
  • Added new features to Content and File
  • Fixed URL regexp bug in HyperlinkUtils?
  • Updated French translations
  • Updates profiles template
  • TODO: Add getNewUI et processNewUI to FavoriteHotspots? to simplify input
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/wifidog/classes/Content/Avatar/Avatar.php

    r1194 r1226  
    5656        $this -> configEnableEditWidthHeight(false); 
    5757        $this -> configEnableHyperlink(false); 
     58 
     59                // Max 40x40 pixels 
     60        $this->setMaxDisplayWidth(40); 
     61        $this->setMaxDisplayHeight(40); 
    5862    } 
    5963 
     
    6266        return $html; 
    6367    } 
     68 
     69    /** 
     70         * Validates the uploaded file and return a boolean to tell if valid 
     71         * This method should be overridden when you need to write special validation scripts 
     72         * 
     73         * @param string path to input file 
     74         * @param string path to output file (by ref.), making sure you create a struct that matches the $_FILES[][] format 
     75         * 
     76         * @return boolean 
     77         */ 
     78        protected function validateUploadedFile($input, &$output) { 
     79                $errmsg = null; 
     80                // Only if GD is available, resize to max size 
     81                if (Dependencies::check("gd", $errmsg)) { 
     82                        // Extract image metadata 
     83                        list($width_orig, $height_orig, $type, $attr) = getimagesize($input['tmp_name']); 
     84                        // Check if it busts the max size 
     85                        if($width_orig > $this->getMaxDisplayWidth() || $height_orig > $this->getMaxDisplayHeight()) { 
     86                                // Init with max values 
     87                                $width = $this->getMaxDisplayWidth(); 
     88                                $height = $this->getMaxDisplayHeight(); 
     89 
     90                                // Compute ratios 
     91                                $ratio_orig = $width_orig / $height_orig; 
     92                                if ($this->getMaxDisplayWidth() / $this->getMaxDisplayHeight() > $ratio_orig) { 
     93                                   $width =  $height * $ratio_orig; 
     94                                } else { 
     95                                   $height = $width / $ratio_orig; 
     96                                } 
     97 
     98                                // Resample 
     99                                $image_p = imagecreatetruecolor($width, $height); 
     100                                $image = imagecreatefromjpeg($input['tmp_name']); 
     101                                imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); 
     102 
     103                                // Build output metadata struct 
     104                                $output = array(); 
     105                                $output['tmp_name'] = tempnam("/tmp", session_id()); 
     106                                $output['type'] = "image/png"; 
     107                                $output['name'] = $input['name']; 
     108 
     109                                // Output PNG at full compression (no artefact) 
     110                                imagepng($image_p, $output['tmp_name'], 9); 
     111 
     112                                // Write new file size 
     113                                $output['size'] = filesize($output['tmp_name']); 
     114                        } 
     115                } 
     116                return true; 
     117        } 
    64118} 
    65119