Ignore:
Timestamp:
Dec 18, 2005 12:16:03 AM (18 years ago)
Author:
scdev
Message:

detabbed all files ;P

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/ImageThumb.inc.php

    r41 r42  
    11<?php
    22/**
    3  * ImageThumb.inc.php 
     3 * ImageThumb.inc.php
    44 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
    55 */
     
    2020
    2121class ImageThumb {
    22    
     22
    2323    // The location for images to create thumbnails from.
    2424    var $source_dir = null;
    25    
     25
    2626    // Specifications for thumbnail images.
    27     var $spec; 
    28    
     27    var $spec;
     28
    2929    // Array of acceptable file extensions (lowercase).
    3030    var $valid_file_extensions = array('jpg', 'jpeg', 'gif', 'png');
    31    
    32     // The uploaded files will be owned by user 'apache'. Set world-read/write 
     31
     32    // The uploaded files will be owned by user 'apache'. Set world-read/write
    3333    // if the website admin needs to read/delete these files. Must be at least 0400 with owner=apache.
    3434    var $dest_file_perms = 0644;
    35    
     35
    3636    // Must be at least 0700 with owner=apache.
    3737    var $dest_dir_perms = 0777;
     
    4242    var $cjpeg_binary = '/usr/bin/cjpeg';
    4343    var $_valid_binaries = true;
    44    
     44
    4545    // Display messages raised in this object?
    4646    var $display_messages = true;
     
    7676    function setSourceDirectory($source_dir)
    7777    {
    78        
     78
    7979        // Set the source directory path, stripping any extra slashes if needed.
    8080        $this->source_dir = preg_replace('!/+$!', '', $source_dir);
    81        
     81
    8282        if (!is_dir($this->source_dir)) {
    8383            App::logMsg(sprintf('ImageThumb error: source directory not found: %s', $this->source_dir), LOG_ERR, __FILE__, __LINE__);
     
    108108        $allow_upscaling = isset($spec['allow_upscaling']) ? $spec['allow_upscaling'] : false;
    109109        $keep_filesize   = isset($spec['keep_filesize']) ? $spec['keep_filesize'] : null;
    110    
     110
    111111        // Define pnmscale arguments.
    112112        switch ($scaling_type) {
     
    144144            break;
    145145        }
    146        
     146
    147147        // Define cjpeg arguments.
    148148        $cjpeg_args = sprintf(' -optimize -quality %s ', escapeshellcmd($quality));
    149149        $cjpeg_args .= (true === $progressive) ? ' -progressive ' : '';
    150        
     150
    151151        $this->spec[] = array(
    152152            'dest_dir' => $dest_dir,
     
    185185            }
    186186        }
    187                
     187
    188188        // If > 0, there was a problem creating dest dirs.
    189189        return (0 == $return_val);
     
    203203            return false;
    204204        }
    205        
     205
    206206        // Ensure we have a source.
    207207        if (!isset($this->source_dir)) {
     
    209209            return false;
    210210        }
    211        
     211
    212212        // To keep this script running even if user tries to stop browser.
    213         ignore_user_abort(true); 
    214         if (!ini_get('safe_mode')) { 
    215             set_time_limit(300); 
    216         }
    217        
     213        ignore_user_abort(true);
     214        if (!ini_get('safe_mode')) {
     215            set_time_limit(300);
     216        }
     217
    218218        // Confirm source image exists.
    219219        if (!file_exists($this->source_dir . '/' . $file_name)) {
     
    222222            return false;
    223223        }
    224        
     224
    225225        // Confirm source image is readable.
    226226        if (!is_readable($this->source_dir . '/' . $file_name)) {
     
    229229            return false;
    230230        }
    231        
     231
    232232        // Confirm source image contains data.
    233233        if (filesize($this->source_dir . '/' . $file_name) < 1) {
     
    236236            return false;
    237237        }
    238        
     238
    239239        // Confirm source image has a valid file extension.
    240240        if (!$this->validFileExtension($file_name)) {
     
    243243            return false;
    244244        }
    245        
     245
    246246        // Output file will be a jpg. Set file extension.
    247247        $file_name = substr($file_name, 0, strrpos($file_name, '.')) . '.jpg';
     
    249249        // This remains zero until something goes wrong.
    250250        $final_return_val = 0;
    251        
     251
    252252        foreach ($this->spec as $s) {
    253        
     253
    254254            // Skip existing thumbnails with file size below $s['keep_filesize'].
    255255            if (file_exists(realpath($this->source_dir . '/' . $s['dest_dir'] . '/' . $file_name)) && isset($s['keep_filesize'])) {
     
    260260                }
    261261            }
    262            
     262
    263263            // Determine if original file size is smaller than specified thumbnail size. Do not scale-up if allow_upscaling config is set to false.
    264264            $image_size = getimagesize(realpath($this->source_dir . '/' . $file_name));
     
    269269                $pnmscale_args = $s['pnmscale_args'];
    270270            }
    271            
     271
    272272            // Execute the command that creates the thumbnail.
    273273            $command = sprintf('%s %s/%s | %s %s | %s %s > %s/%s',
     
    278278                escapeshellcmd($pnmscale_args),
    279279                escapeshellcmd($this->cjpeg_binary),
    280                 escapeshellcmd($s['cjpeg_args']), 
     280                escapeshellcmd($s['cjpeg_args']),
    281281                escapeshellcmd(realpath($this->source_dir . '/' . $s['dest_dir'])),
    282282                escapeshellcmd($file_name)
     
    292292                App::logMsg(sprintf('Image %s failed resizing with return value: %s%s', $s['dest_dir'] . '/' . $file_name, $return_val, empty($output) ? '' : ' (' . getDump($output) . ')'), LOG_ERR, __FILE__, __LINE__);
    293293            }
    294            
     294
    295295            // Return from the command will be > 0 if there was an error.
    296296            $final_return_val += $return_val;
    297297        }
    298        
     298
    299299        // If > 0, there was a problem thumbnailing.
    300300        return (0 == $final_return_val);
     
    314314            return false;
    315315        }
    316        
     316
    317317        // Get all files in source directory.
    318318        $dir_handle = opendir($this->source_dir);
     
    323323            }
    324324        }
    325        
     325
    326326        // Process each found file.
    327327        if (is_array($files) && !empty($files)) {
     
    350350            return false;
    351351        }
    352        
     352
    353353        $ret = 0;
    354354        foreach ($this->spec as $s) {
     
    379379            return false;
    380380        }
    381        
     381
    382382        $file_path_name = $this->source_dir . '/' . $file_name;
    383383        if (!unlink($file_path_name)) {
     
    388388        return true;
    389389    }
    390    
     390
    391391    /**
    392392     * Returns true if file exists.
     
    403403            return false;
    404404        }
    405        
     405
    406406        return file_exists($this->source_dir . '/' . $file_name);
    407407    }
    408    
     408
    409409    /**
    410410     * Tests if extention of $file_name is in the array valid_file_extensions.
     
    419419        return in_array(strtolower($ext[1]), $this->valid_file_extensions);
    420420    }
    421    
     421
    422422    /**
    423423     * An alias for App::raiseMsg that only sends messages if display_messages is true.
Note: See TracChangeset for help on using the changeset viewer.