/** * Called once for each image in the archive. * @param COMPRESSED_FILE $archive * @param COMPRESSED_FILE_ENTRY $entry * @param WEBCORE_CALLBACK $error_callback * @access private */ public function process_image($archive, $entry, $error_callback) { log_open_block("Extracting [{$entry->name}]..."); $entry->extract_to($this->_target_directory, $error_callback); $class_name = $this->app->final_class_name('IMAGE', 'webcore/util/image.php'); /** @var IMAGE $img */ $img = new $class_name(); $img->set_file($entry->extracted_name, $this->read_exif); if ($img->loadable()) { $img->load_from_file(); $url = new FILE_URL($entry->extracted_name); if ($this->create_thumbnail) { if ($img->saveable()) { $url->append_to_name('_tn'); $thumbnail_name = $url->as_text(); $this->_log("Creating thumbnail...", Msg_type_info); $img->resize_to_fit($this->thumbnail_size, $this->thumbnail_size); $img->save_to_file($thumbnail_name); } else { $this->_log("Could not create thumbnail.", Msg_type_error); } } $pic_date = $this->default_date; if ($this->read_exif) { if ($img->properties->exists() && $img->properties->time_created->is_valid()) { $pic_date = $img->properties->time_created; } else { $this->_log("Could not read date from file (using default).", Msg_type_warning); } } $original_url = new FILE_URL($entry->name); $file_name_only = $original_url->name_without_extension(); $pic_title = $this->file_name_template; $pic_title = str_replace('{#}', $this->_num_pictures_imported + $this->starting_index, $pic_title); $pic_title = str_replace('{file}', $file_name_only, $pic_title); $pic = $this->_folder->new_object('picture'); $pic->title = $pic_title; $pic->file_name = $entry->normalized_name; $pic->date = $pic_date; $history_item = $pic->new_history_item(); $pic->store_if_different($history_item); $this->_num_pictures_imported = $this->_num_pictures_imported + 1; $this->_log("Created picture [{$pic->title}]", Msg_type_info); } else { $php_errormsg = null; @unlink($entry->extracted_name); if (isset($php_errormsg)) { $this->_log("This is not an image file (could not delete file on server): " . $php_errormsg, Msg_type_error); } else { $this->_log("This is not an image file (file was deleted on the server).", Msg_type_warning); } } log_close_block(); }