/** * Imagick by default can't handle s3:// paths * for saving images. We have instead save it to a file file, * then copy it to the s3:// path as a workaround. */ protected function _save($image, $filename = null, $mime_type = null) { list($filename, $extension, $mime_type) = $this->get_output_format($filename, $mime_type); if (!$filename) { $filename = $this->generate_filename(null, null, $extension); } $upload_dir = wp_upload_dir(); if (strpos($filename, $upload_dir['basedir']) === 0) { $temp_filename = tempnam(get_temp_dir(), 's3-uploads'); } $save = parent::_save($image, $temp_filename, $mime_type); if (is_wp_error($save)) { return $save; } $copy_result = copy($save['path'], $filename); unlink($save['path']); if (!$copy_result) { return new WP_Error('unable-to-copy-to-s3', 'Unable to copy the temp image to S3'); } return array('path' => $filename, 'file' => wp_basename(apply_filters('image_make_intermediate_size', $filename)), 'width' => $this->size['width'], 'height' => $this->size['height'], 'mime-type' => $mime_type); }