Location: PHPKode > projects > photolibrary > function.redrawimage.php
<?PHP
/*
   [Start: Program Information Header]

    Name    : Photolibrary: Redraw image
    Purpose : Image redrawing functions (change of rotation, image edited)
    Syntax  :

   [End: Program Information Header]

   [Start: Author Information Header]

    Name    : James D. Forrester
    E-mail  : hide@address.com

    Name    : Ed Sanders
    E-mail  : hide@address.com

   [End: Author Information Header]
*/

function redraw_view($hash, $edited_hash, $type, $width, $height, $orientation = 0)
{
  global $settings;

  if($edited_hash)
  {
    $input_dir = $settings['edited_directory'];
    $output_dir = $settings['edited_directory'].'/views';
    $orientation = 0;
    list($width, $height) = getimagesize($settings['edited_directory'].'/'.filename($hash).'.'.type($type));
  }
  else
  {
    $input_dir = $settings['originals_directory'];
    $output_dir = $settings['views_directory'];
  }

  $view_size = $settings['view_size'];
  if($settings['never_enlarge'])
  {
    if($settings['view_use_pixels'] and $settings['view_size']>$width*$height)
      $view_size = $width*$height;

    if(!$settings['view_use_pixels'] and $settings['view_size']>max($width,$height))
      $view_size = max($width, $height);
  }

  resizeimage(filename($hash).'.'.type($type), '', $input_dir, $output_dir, $view_size, $type, $orientation, '', $settings['view_use_pixels']);
}

function redraw_thumb($hash, $edited_hash, $type, $width, $height, $orientation = 0)
{
  global $settings;

  if($edited_hash != '')
  {
    edit_thumb($hash, $type);
  }
  else if($image = @exif_thumbnail($settings['originals_directory'].'/'.filename($hash).'.'.type($type)))
  {
    $exif_thumb = fopen($settings['thumbs_directory'].'/'.filename($hash).'.'.type($type).'.exif', 'w');
    fwrite($exif_thumb, $image);
    fclose($exif_thumb);
    list($thumb_width, $thumb_height) = getImageSize($settings['thumbs_directory'].'/'.filename($hash).'.'.type($type).'.exif');
    //Check for correct orientation, and size big enough
    if((($width / $height) - 1) * (($thumb_width / $thumb_height) - 1) > 0 and max($thumb_width, $thumb_height) >= $settings['thumb_size'])
    {
      resizeimage(filename($hash).'.'.type($type).'.exif', filename($hash).'.'.type($type), $settings['thumbs_directory'], $settings['thumbs_directory'], $settings['thumb_size'], $type, $orientation, '', 0, $settings['thumb_sharpness']);
    }
    else
    {
      resizeimage(filename($hash).'.'.type($type), '', $settings['originals_directory'], $settings['thumbs_directory'], $settings['thumb_size'], $type, $orientation, '', 0, $settings['thumb_sharpness']);
    }
    unlink($settings['thumbs_directory'].'/'.filename($hash).'.'.type($type).'.exif'); // Delete EXIF thumb
  }
  else
  {
    resizeimage(filename($hash).'.'.type($type), '', $settings['originals_directory'], $settings['thumbs_directory'], $settings['thumb_size'], $type, $orientation, '', 0, $settings['thumb_sharpness']);
  }
}

function redraw_edit($hash, $edited_hash, $type, $width, $height)
{
  global $settings;

  if(!file_exists($settings['edited_directory'].'/'.filename($hash).'.'.type($type)))
    copy($settings['originals_directory'].'/'.filename($hash).'.'.type($type), $settings['edited_directory'].'/'.filename($hash).'.'.type($type));

  $current_hash = md5_file($settings['edited_directory'].'/'.filename($hash).'.'.type($type));
  if($current_hash != $edited_hash or !file_exists($settings['edited_directory'].'/views/'.filename($hash).'.'.type($type)))
  {
    redraw_view($hash, $edited_hash, $type, $width, $height, 0);
    mysql_query("UPDATE photos SET edited_hash = '$current_hash' WHERE hash = '$hash'") or trigger_error(mysql_error(), E_USER_ERROR);
    edit_thumb($hash, $type);
  }
  if(!file_exists($settings['thumbs_directory'].'/'.filename($hash).'.'.type($type)))
    edit_thumb($hash, $type);
}

function edit_thumb($hash, $type)
{
  global $settings;

  resizeimage(filename($hash).'.'.type($type), '', $settings['edited_directory'].'/views', $settings['thumbs_directory'], $settings['thumb_size'], $type, 0, '', 0, $settings['thumb_sharpness']);
}

?>
Return current item: photolibrary