You are here

function imagefield_crop_create_copy in Imagefield Crop 7.3

Same name and namespace in other branches
  1. 7.2 imagefield_crop.module \imagefield_crop_create_copy()

Creates a copy of the file.

Parameters

$file:

Return value

stdClass

2 calls to imagefield_crop_create_copy()
imagefield_crop_field_insert in ./imagefield_crop.module
Implements hook_field_insert().
imagefield_crop_field_update in ./imagefield_crop.module
Implements hook_field_update().

File

./imagefield_crop.module, line 899

Code

function imagefield_crop_create_copy($file) {
  if ($file->filemime == 'image/gif') {
    $realpath = drupal_realpath($file->uri);
    $new_uri = file_destination(substr($file->uri, 0, -4) . '.jpeg', FILE_EXISTS_RENAME);
    $image = image_load($realpath);
    $image->info['extension'] = 'jpeg';
    $image->info['mime_type'] = 'image/jpeg';
    $success = image_gd_save($image, $new_uri);
    if ($success) {
      $file->uri = $new_uri;
      $file->filename = basename($new_uri);
      $file->filemime = 'image/jpeg';
      file_save($file);
      file_unmanaged_delete($realpath);
    }
  }
  $new_uri = file_unmanaged_copy($file->uri, $file->uri);
  $new_file = clone $file;
  $new_file->fid = 0;
  $new_file->status = FILE_STATUS_PERMANENT;
  $new_file->uri = $new_uri;
  $new_file->filename = basename($new_uri);
  return file_save($new_file);

  //  return $new_file;
}