function imagefield_crop_create_copy in Imagefield Crop 7.2
Same name and namespace in other branches
- 7.3 imagefield_crop.module \imagefield_crop_create_copy()
Creates a copy of the file.
Parameters
object $file: File to copy.
Return value
object Copied file.
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 1039 - Functionality and Drupal hook implementations for the Imagefield Crop module.
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 = drupal_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 = drupal_basename($new_uri);
return file_save($new_file);
}