Esempio n. 1
0
 function create_local_files_and_thumbnails($original_file, $prefix, $options = array())
 {
     $fullsize_jpg = $this->reduced_original($original_file, $prefix, $options);
     if (!file_exists($fullsize_jpg)) {
         write_to_resource_harvesting_log("ContentManager: Unable to create jpg file from downloaded file {$original_file}");
         trigger_error("ContentManager: Unable to create jpg file from downloaded file {$original_file}.", E_USER_NOTICE);
         return false;
     }
     //get the size from the jpg version, which is properly orientated
     $sizes = getimagesize($fullsize_jpg);
     $width = @$sizes[0];
     $height = @$sizes[1];
     if (empty($width) && empty($height)) {
         write_to_resource_harvesting_log("ContentManager: Unable to getimagesize for {$fullsize_jpg}: using default crop and not recording image_size data");
         trigger_error("ContentManager: Unable to getimagesize for {$fullsize_jpg}: using default crop and not recording image_size data", E_USER_NOTICE);
     }
     // we make an exception
     if (isset($options['large_image_dimensions']) && is_array($options['large_image_dimensions'])) {
         $large_image_dimensions = $options['large_image_dimensions'];
     } else {
         $large_image_dimensions = ContentManager::large_image_dimensions();
     }
     //create smaller versions, or hard-link to them if $fullsize_jpg is a previously existing file
     $large_jpg = $this->create_smaller_version($fullsize_jpg, $large_image_dimensions, $prefix, implode(ContentManager::large_image_dimensions(), '_'));
     //use large (not fullsize) jpg to create the medium & small versions, to save processing potentially enormous _orig.jpg files.
     $this->create_smaller_version($large_jpg, ContentManager::medium_image_dimensions(), $prefix, implode(ContentManager::medium_image_dimensions(), '_'));
     $this->create_smaller_version($large_jpg, ContentManager::small_image_dimensions(), $prefix, implode(ContentManager::small_image_dimensions(), '_'));
     $custom_crop = $this->check_image_database(@$options['data_object_id'], @$options['data_object_guid']);
     if (isset($options['crop_pct']) && count($options['crop_pct']) >= 4) {
         $custom_crop = $options['crop_pct'];
     }
     if (count($custom_crop) >= 4) {
         foreach ($custom_crop as &$p) {
             $p = min(max($p, 0), 100);
         }
         $crop_pixels = array(intval(round($custom_crop[0] / 100.0 * $width)), intval(round($custom_crop[1] / 100.0 * $height)), intval(round($custom_crop[2] / 100.0 * $width)));
         $crop_pixels[] = empty($custom_crop[3]) ? $crop_pixels[2] : intval(round($custom_crop[3] / 100.0 * $height));
         //if this image has a custom crop, it could be of a tiny region, so use the huge image, to avoid pixellation.
         //Ideally, we'd use the original image but it could be rotated differently, and we don't currently store rotation information in the DB.
         $this->create_crop($fullsize_jpg, ContentManager::large_square_dimensions(), $prefix, $crop_pixels);
         $this->create_crop($fullsize_jpg, ContentManager::small_square_dimensions(), $prefix, $crop_pixels);
     } else {
         //we are taking the default crop, so to save cpu time, don't bother cropping the full size image, just use the "large" 580_360 version
         $this->create_crop($large_jpg, ContentManager::large_square_dimensions(), $prefix);
         $this->create_crop($large_jpg, ContentManager::small_square_dimensions(), $prefix);
     }
     //update width & height in case they have changed, but only change % crop values if we have a $new_crop
     $this->save_image_size_data(@$options['data_object_id'], $width, $height, $custom_crop);
 }