You are here

function _imce_unzip_scale_image in IMCE unzip 6

Same name and namespace in other branches
  1. 7 imce_unzip.module \_imce_unzip_scale_image()

Private function for scaling and saving images.

1 call to _imce_unzip_scale_image()
_imce_unzip_file_unzip in ./imce_unzip.module
Unzip the files and check extensions.

File

./imce_unzip.module, line 340
Main functions for IMCE unzip module

Code

function _imce_unzip_scale_image($imce, $file, $start_width, $maxw, $start_height, $maxh, $buf) {
  $temp = tempnam(realpath(file_directory_temp()), 'imc');
  register_shutdown_function('file_delete', $temp);
  $fp = fopen($temp, "w+");
  fwrite($fp, $buf);
  fclose($fp);
  $new_width = $maxw == 0 ? $start_width : $maxw;
  $new_height = $maxh == 0 ? $start_height : $maxh;
  if (!image_scale($temp, $file->filepath, $new_width, $new_height)) {
    drupal_set_message(t('Can not scale image %filename', array(
      '%filename' => $file->filepath,
    ), 'error'));
    return FALSE;
  }
  @chmod($file->filepath, 0664);
  $update = array();
  if ($_file = db_fetch_object(db_query("SELECT f.* FROM {files} f WHERE f.filepath = '%s'", $file->filepath))) {
    $file->fid = $_file->fid;
    $file->uid = $_file->uid;
    $update[] = 'fid';
  }

  // Save the file.
  drupal_write_record('files', $file, $update);
  $img = imce_image_info($file->filepath);
  $file->width = $img['width'];
  $file->height = $img['height'];
  imce_add_file($file, $imce);
  return $file;
}