imagetools.php
author Dan
Fri, 12 Jun 2009 11:57:08 -0400
changeset 74 7719085707d8
parent 73 1f55c324efcf
permissions -rw-r--r--
Security: Sessions are now based on HMAC-MD5 salts instead of concatenation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
     1
<?php
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
     2
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
     3
/**
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
     4
 * Greyhound - real web management for Amarok
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
     5
 * Copyright (C) 2008 Dan Fuhry
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
     6
 *
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
     7
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
     8
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
     9
 *
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    11
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    12
 */
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    13
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    14
/**
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    15
 * Determines an image's filetype based on its signature.
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    16
 * @param string Path to image file
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    17
 * @return string One of gif, png, or jpg, or false if none of these.
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    18
 */
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    19
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    20
function get_image_filetype($filename)
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    21
{
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    22
  $filecontents = @file_get_contents($filename);
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    23
  if ( empty($filecontents) )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    24
    return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    25
  
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    26
  if ( substr($filecontents, 0, 8) == "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    27
    return 'png';
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    28
  
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    29
  if ( substr($filecontents, 0, 6) == 'GIF87a' || substr($filecontents, 0, 6) == 'GIF89a' )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    30
    return 'gif';
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    31
  
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    32
  if ( substr($filecontents, 0, 2) == "\xFF\xD8" )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    33
    return 'jpg';
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    34
  
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    35
  return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    36
}
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    37
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    38
/**
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    39
 * Scales an image to the specified width and height, and writes the output to the specified
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    40
 * file. Will use ImageMagick if present, but if not will attempt to scale with GD. This will
40
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
    41
 * always scale images proportionally, unless $preserve_ratio is set to false.
25
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    42
 * 
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    43
 * Ported from Enano CMS (which is also my project)
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    44
 * 
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    45
 * @param string Path to image file
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    46
 * @param string Path to output file
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    47
 * @param int Image width, in pixels
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    48
 * @param int Image height, in pixels
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    49
 * @param bool If true, the output file will be deleted if it exists before it is written
40
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
    50
 * @param bool If true, preserves the image's aspect ratio (default)
25
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    51
 * @return bool True on success, false on failure
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    52
 */
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    53
40
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
    54
function scale_image($in_file, $out_file, $width = 225, $height = 225, $unlink = false, $preserve_ratio = true)
25
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    55
{
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    56
  global $db, $session, $paths, $template, $plugins; // Common objects
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    57
  
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    58
  if ( !is_int($width) || !is_int($height) )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    59
    return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    60
  
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    61
  if ( !file_exists($in_file) )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    62
    return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    63
  
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    64
  if ( preg_match('/["\'\/\\]/', $in_file) || preg_match('/["\'\/\\]/', $out_file) )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    65
    return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    66
  
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    67
  if ( file_exists($out_file) && !$unlink )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    68
    return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    69
  else if ( file_exists($out_file) && $unlink )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    70
    @unlink($out_file);
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    71
  if ( file_exists($out_file) )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    72
    // couldn't unlink (delete) the output file
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    73
    return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    74
    
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    75
  $file_ext = substr($in_file, ( strrpos($in_file, '.') + 1));
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    76
  switch($file_ext)
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    77
  {
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    78
    case 'png':
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    79
      $func = 'imagecreatefrompng';
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    80
      break;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    81
    case 'jpg':
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    82
    case 'jpeg':
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    83
      $func = 'imagecreatefromjpeg';
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    84
      break;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    85
    case 'gif':
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    86
      $func = 'imagecreatefromgif';
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    87
      break;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    88
    case 'xpm':
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    89
      $func = 'imagecreatefromxpm';
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    90
      break;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    91
    default:
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    92
      return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    93
  }
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    94
    
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    95
  // try to find convert in the PATH
73
1f55c324efcf Image tools: Use which() instead of reimplementing (should also work on win32 now)
Dan
parents: 40
diff changeset
    96
  $magick_path = which('convert');
25
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    97
  
73
1f55c324efcf Image tools: Use which() instead of reimplementing (should also work on win32 now)
Dan
parents: 40
diff changeset
    98
  $can_use_magick = !empty($magick_path);
25
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
    99
  $can_use_gd = (
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   100
      function_exists('getimagesize')         &&
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   101
      function_exists('imagecreatetruecolor') &&
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   102
      function_exists('imagecopyresampled')   &&
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   103
      function_exists($func)
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   104
    );
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   105
  if ( $can_use_magick )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   106
  {
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   107
    if ( !preg_match('/^([\/A-z0-9_-]+)$/', $magick_path) )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   108
    {
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   109
      // ImageMagick path seems screwy
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   110
      return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   111
    }
40
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   112
    $op = ( $preserve_ratio ) ? '>' : '!';
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   113
    $cmdline = "\"$magick_path\" \"$in_file\" -resize '{$width}x{$height}$op' \"$out_file\"";
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   114
    exec($cmdline, $output, $return);
25
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   115
    if ( !file_exists($out_file) )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   116
      return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   117
    return true;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   118
  }
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   119
  else if ( $can_use_gd )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   120
  {
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   121
    @list($width_orig, $height_orig) = @getimagesize($in_file);
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   122
    if ( !$width_orig || !$height_orig )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   123
      return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   124
    // calculate new width and height
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   125
    
40
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   126
    if ( $preserve_ratio )
25
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   127
    {
40
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   128
      $ratio = $width_orig / $height_orig;
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   129
      if ( $ratio > 1 )
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   130
      {
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   131
        // orig. width is greater that height
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   132
        $new_width = $width;
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   133
        $new_height = round( $width / $ratio );
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   134
      }
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   135
      else if ( $ratio < 1 )
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   136
      {
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   137
        // orig. height is greater than width
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   138
        $new_width = round( $height / $ratio );
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   139
        $new_height = $height;
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   140
      }
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   141
      else if ( $ratio == 1 )
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   142
      {
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   143
        $new_width = $width;
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   144
        $new_height = $width;
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   145
      }
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   146
      if ( $new_width > $width_orig || $new_height > $height_orig )
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   147
      {
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   148
        // Too big for our britches here; set it to only convert the file
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   149
        $new_width = $width_orig;
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   150
        $new_height = $height_orig;
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   151
      }
25
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   152
    }
40
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   153
    else
25
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   154
    {
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   155
      $new_width = $width;
40
bd3372a2afc1 Added artwork spriting support. Artwork is now displayed using a gigantic CSS sprite instead of hundreds of little images. GD required.
Dan
parents: 25
diff changeset
   156
      $new_height = $height;
25
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   157
    }
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   158
    
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   159
    $newimage = @imagecreatetruecolor($new_width, $new_height);
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   160
    if ( !$newimage )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   161
      return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   162
    $oldimage = @$func($in_file);
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   163
    if ( !$oldimage )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   164
      return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   165
    
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   166
    // Perform scaling
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   167
    imagecopyresampled($newimage, $oldimage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   168
    
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   169
    // Get output format
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   170
    $out_ext = substr($out_file, ( strrpos($out_file, '.') + 1));
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   171
    switch($out_ext)
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   172
    {
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   173
      case 'png':
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   174
        $outfunc = 'imagepng';
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   175
        break;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   176
      case 'jpg':
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   177
      case 'jpeg':
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   178
        $outfunc = 'imagejpeg';
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   179
        break;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   180
      case 'gif':
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   181
        $outfunc = 'imagegif';
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   182
        break;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   183
      case 'xpm':
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   184
        $outfunc = 'imagexpm';
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   185
        break;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   186
      default:
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   187
        imagedestroy($newimage);
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   188
        imagedestroy($oldimage);
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   189
        return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   190
    }
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   191
    
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   192
    // Write output
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   193
    $outfunc($newimage, $out_file);
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   194
    
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   195
    // clean up
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   196
    imagedestroy($newimage);
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   197
    imagedestroy($oldimage);
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   198
    
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   199
    // done!
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   200
    return true;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   201
  }
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   202
  if ( file_exists($out_file) )
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   203
    return true;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   204
  return false;
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   205
}
5c377ceb0e4c Added initial album artwork support.
Dan
parents:
diff changeset
   206