本文整理汇总了PHP中wp_crop_image函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_crop_image函数的具体用法?PHP wp_crop_image怎么用?PHP wp_crop_image使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_crop_image函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
function process()
{
if (isset($_POST['upload'])) {
check_admin_referer('thesis-header-upload', '_wpnonce-thesis-header-upload');
#wp
$overrides = array('test_form' => false);
$file = wp_handle_upload($_FILES['import'], $overrides);
#wp
if (isset($file['error'])) {
wp_die($file['error'], __('Image Upload Error', 'thesis'));
}
#wp
if ($file['type'] == 'image/jpeg' || $file['type'] == 'image/pjpeg' || $file['type'] == 'image/png' || $file['type'] == 'image/gif') {
$this->url = $file['url'];
$image = $file['file'];
list($this->width, $this->height) = getimagesize($image);
if ($this->width <= $this->optimal_width) {
$this->save($image);
} elseif ($this->width > $this->optimal_width) {
if (apply_filters('thesis_crop_header', true)) {
#filter
$this->ratio = $this->width / $this->optimal_width;
$cropped = wp_crop_image($image, 0, 0, $this->width, $this->height, $this->optimal_width, $this->height / $this->ratio, false, str_replace(basename($image), 'cropped-' . basename($image), $image));
#wp
if (is_wp_error($cropped)) {
#wp
wp_die(__('Your image could not be processed. Please go back and try again.', 'thesis'), __('Image Processing Error', 'thesis'));
}
#wp
$this->url = str_replace(basename($this->url), basename($cropped), $this->url);
$this->width = round($this->width / $this->ratio);
$this->height = round($this->height / $this->ratio);
$this->save($cropped);
@unlink($image);
} else {
$this->save($image);
}
}
} else {
$this->error = true;
}
} elseif ($_GET['remove']) {
check_admin_referer('thesis-remove-header');
#wp
unset($this->header);
delete_option('thesis_header');
#wp
global $thesis_design;
if (!$thesis_design->display['header']['tagline'] && apply_filters('thesis_header_auto_tagline', true)) {
#filter
$thesis_design->display['header']['tagline'] = true;
update_option('thesis_design_options', $thesis_design);
#wp
}
thesis_generate_css();
$this->removed = true;
}
}
示例2: ajax_header_crop
/**
* Gets attachment uploaded by Media Manager, crops it, then saves it as a
* new object. Returns JSON-encoded object details.
*/
public function ajax_header_crop()
{
check_ajax_referer('image_editor-' . $_POST['id'], 'nonce');
if (!current_user_can('edit_theme_options')) {
wp_send_json_error();
}
if (!current_theme_supports('custom-header', 'uploads')) {
wp_send_json_error();
}
$crop_details = $_POST['cropDetails'];
$dimensions = $this->get_header_dimensions(array('height' => $crop_details['height'], 'width' => $crop_details['width']));
$attachment_id = absint($_POST['id']);
$cropped = wp_crop_image($attachment_id, (int) $crop_details['x1'], (int) $crop_details['y1'], (int) $crop_details['width'], (int) $crop_details['height'], (int) $dimensions['dst_width'], (int) $dimensions['dst_height']);
if (!$cropped || is_wp_error($cropped)) {
wp_send_json_error(array('message' => __('Image could not be processed. Please go back and try again.')));
}
/** This filter is documented in wp-admin/custom-header.php */
$cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id);
// For replication
$object = $this->create_attachment_object($cropped, $attachment_id);
unset($object['ID']);
$new_attachment_id = $this->insert_attachment($object, $cropped);
$object['attachment_id'] = $new_attachment_id;
$object['width'] = $dimensions['dst_width'];
$object['height'] = $dimensions['dst_height'];
wp_send_json_success($object);
}
示例3: wp_ajax_crop_image
/**
* AJAX handler for cropping an image.
*
* @since 4.3.0
*
* @global WP_Site_Icon $wp_site_icon
*/
function wp_ajax_crop_image()
{
$attachment_id = absint($_POST['id']);
check_ajax_referer('image_editor-' . $attachment_id, 'nonce');
if (!current_user_can('customize')) {
wp_send_json_error();
}
$context = str_replace('_', '-', $_POST['context']);
$data = array_map('absint', $_POST['cropDetails']);
$cropped = wp_crop_image($attachment_id, $data['x1'], $data['y1'], $data['width'], $data['height'], $data['dst_width'], $data['dst_height']);
if (!$cropped || is_wp_error($cropped)) {
wp_send_json_error(array('message' => __('Image could not be processed.')));
}
switch ($context) {
case 'site-icon':
require_once ABSPATH . '/wp-admin/includes/class-wp-site-icon.php';
global $wp_site_icon;
/** This filter is documented in wp-admin/custom-header.php */
$cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id);
// For replication.
$object = $wp_site_icon->create_attachment_object($cropped, $attachment_id);
unset($object['ID']);
// Update the attachment.
add_filter('intermediate_image_sizes_advanced', array($wp_site_icon, 'additional_sizes'));
$attachment_id = $wp_site_icon->insert_attachment($object, $cropped);
remove_filter('intermediate_image_sizes_advanced', array($wp_site_icon, 'additional_sizes'));
// Additional sizes in wp_prepare_attachment_for_js().
add_filter('image_size_names_choose', array($wp_site_icon, 'additional_sizes'));
break;
default:
/**
* Filters the attachment id for a cropped image.
*
* @since 4.3.0
*
* @param int $attachment_id The ID of the cropped image.
* @param string $context The feature requesting the cropped image.
*/
$attachment_id = apply_filters('wp_ajax_cropped_attachment_id', 0, $context);
if (!$attachment_id) {
wp_send_json_error();
}
}
wp_send_json_success(wp_prepare_attachment_for_js($attachment_id));
}
示例4: wp_ajax_crop_image
/**
* AJAX handler for cropping an image.
*
* @since 4.3.0
*
* @global WP_Site_Icon $wp_site_icon
*/
function wp_ajax_crop_image()
{
$attachment_id = absint($_POST['id']);
check_ajax_referer('image_editor-' . $attachment_id, 'nonce');
if (!current_user_can('customize')) {
wp_send_json_error();
}
$context = str_replace('_', '-', $_POST['context']);
$data = array_map('absint', $_POST['cropDetails']);
$cropped = wp_crop_image($attachment_id, $data['x1'], $data['y1'], $data['width'], $data['height'], $data['dst_width'], $data['dst_height']);
if (!$cropped || is_wp_error($cropped)) {
wp_send_json_error(array('message' => __('Image could not be processed.')));
}
switch ($context) {
case 'site-icon':
require_once ABSPATH . '/wp-admin/includes/class-wp-site-icon.php';
global $wp_site_icon;
// Skip creating a new attachment if the attachment is a Site Icon.
if (get_post_meta($attachment_id, '_wp_attachment_context', true) == $context) {
// Delete the temporary cropped file, we don't need it.
wp_delete_file($cropped);
// Additional sizes in wp_prepare_attachment_for_js().
add_filter('image_size_names_choose', array($wp_site_icon, 'additional_sizes'));
break;
}
/** This filter is documented in wp-admin/custom-header.php */
$cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id);
// For replication.
$object = $wp_site_icon->create_attachment_object($cropped, $attachment_id);
unset($object['ID']);
// Update the attachment.
add_filter('intermediate_image_sizes_advanced', array($wp_site_icon, 'additional_sizes'));
$attachment_id = $wp_site_icon->insert_attachment($object, $cropped);
remove_filter('intermediate_image_sizes_advanced', array($wp_site_icon, 'additional_sizes'));
// Additional sizes in wp_prepare_attachment_for_js().
add_filter('image_size_names_choose', array($wp_site_icon, 'additional_sizes'));
break;
default:
/**
* Fires before a cropped image is saved.
*
* Allows to add filters to modify the way a cropped image is saved.
*
* @since 4.3.0
*
* @param string $context The Customizer control requesting the cropped image.
* @param int $attachment_id The attachment ID of the original image.
* @param string $cropped Path to the cropped image file.
*/
do_action('wp_ajax_crop_image_pre_save', $context, $attachment_id, $cropped);
/** This filter is documented in wp-admin/custom-header.php */
$cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id);
// For replication.
$parent_url = wp_get_attachment_url($attachment_id);
$url = str_replace(basename($parent_url), basename($cropped), $parent_url);
$size = @getimagesize($cropped);
$image_type = $size ? $size['mime'] : 'image/jpeg';
$object = array('post_title' => basename($cropped), 'post_content' => $url, 'post_mime_type' => $image_type, 'guid' => $url, 'context' => $context);
$attachment_id = wp_insert_attachment($object, $cropped);
$metadata = wp_generate_attachment_metadata($attachment_id, $cropped);
/**
* Filter the cropped image attachment metadata.
*
* @since 4.3.0
*
* @see wp_generate_attachment_metadata()
*
* @param array $metadata Attachment metadata.
*/
$metadata = apply_filters('wp_ajax_cropped_attachment_metadata', $metadata);
wp_update_attachment_metadata($attachment_id, $metadata);
/**
* Filter the attachment ID for a cropped image.
*
* @since 4.3.0
*
* @param int $attachment_id The attachment ID of the cropped image.
* @param string $context The Customizer control requesting the cropped image.
*/
$attachment_id = apply_filters('wp_ajax_cropped_attachment_id', $attachment_id, $context);
}
wp_send_json_success(wp_prepare_attachment_for_js($attachment_id));
}
示例5: step_3
/**
* Display third step of custom header image page.
*
* @since unknown
*/
function step_3()
{
check_admin_referer('custom-header');
if ($_POST['oitar'] > 1) {
$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
$_POST['width'] = $_POST['width'] * $_POST['oitar'];
$_POST['height'] = $_POST['height'] * $_POST['oitar'];
}
$original = get_attached_file($_POST['attachment_id']);
$cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT);
$cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']);
// For replication
$parent = get_post($_POST['attachment_id']);
$parent_url = $parent->guid;
$url = str_replace(basename($parent_url), basename($cropped), $parent_url);
// Construct the object array
$object = array('ID' => $_POST['attachment_id'], 'post_title' => basename($cropped), 'post_content' => $url, 'post_mime_type' => 'image/jpeg', 'guid' => $url);
// Update the attachment
wp_insert_attachment($object, $cropped);
wp_update_attachment_metadata($_POST['attachment_id'], wp_generate_attachment_metadata($_POST['attachment_id'], $cropped));
set_theme_mod('header_image', $url);
// cleanup
$medium = str_replace(basename($original), 'midsize-' . basename($original), $original);
@unlink(apply_filters('wp_delete_file', $medium));
@unlink(apply_filters('wp_delete_file', $original));
return $this->finished();
}
示例6: bp_core_avatar_cropstore
function bp_core_avatar_cropstore($source, $canvas, $v1_x1, $v1_y1, $v1_w, $v1_h, $v2_x1, $v2_y1, $v2_w, $v2_h, $from_signup = false, $filename = 'avatar', $item_id = null)
{
$size = getimagesize($source);
$dims = getimagesize($canvas);
// Figure out multiplier for scaling
$multi = $size[0] / $dims[0];
if ($item_id) {
$filename_item_id = $item_id . '-';
}
if ($filename != 'avatar') {
$v1_filename = '-' . $filename_item_id . $filename . '-thumb';
$v2_filename = '-' . $filename_item_id . $filename . '-full';
} else {
$v1_filename = '-avatar1';
$v2_filename = '-avatar2';
}
$v1_filename = apply_filters('bp_avatar_v1_filename', $v1_filename);
$v2_filename = apply_filters('bp_avatar_v2_filename', $v2_filename);
// Perform v1 crop
$v1_dest = apply_filters('bp_avatar_v1_dest', dirname($source) . '/' . preg_replace('!(\\.[^.]+)?$!', $v1_filename . '$1', basename($source), 1), $source);
if ($from_signup) {
$v1_out = wp_crop_image($source, $v1_x1, $v1_y1, $v1_w, $v1_h, CORE_AVATAR_V1_W, CORE_AVATAR_V1_H, false, $v1_dest);
} else {
$v1_out = wp_crop_image($source, $v1_x1 * $multi, $v1_y1 * $multi, $v1_w * $multi, $v1_h * $multi, CORE_AVATAR_V1_W, CORE_AVATAR_V1_H, false, $v1_dest);
}
// Perform v2 crop
if (CORE_AVATAR_V2_W !== false && CORE_AVATAR_V2_H !== false) {
$v2_dest = apply_filters('bp_avatar_v2_dest', dirname($source) . '/' . preg_replace('!(\\.[^.]+)?$!', $v2_filename . '$1', basename($source), 1), $source);
if ($from_signup) {
$v2_out = wp_crop_image($source, $v2_x1, $v2_y1, $v2_w, $v2_h, CORE_AVATAR_V2_W, CORE_AVATAR_V2_H, false, $v2_dest);
} else {
$v2_out = wp_crop_image($source, $v2_x1 * $multi, $v2_y1 * $multi, $v2_w * $multi, $v2_h * $multi, CORE_AVATAR_V2_W, CORE_AVATAR_V2_H, false, $v2_dest);
}
}
// Clean up canvas and original images used during cropping
foreach (array(str_replace('..', '', $source), str_replace('..', '', $canvas)) as $f) {
@unlink($f);
}
$dir = $source;
do {
$dir = dirname($dir);
@rmdir($dir);
// will fail on non-empty directories
} while (substr_count($dir, '/') >= 2 && stristr($dir, ABSPATH));
return apply_filters('bp_core_avatar_cropstore', array('v1_out' => $v1_out, 'v2_out' => $v2_out));
}
示例7: step_3
function step_3() {
if ( $_POST['oitar'] > 1 ) {
$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
$_POST['width'] = $_POST['width'] * $_POST['oitar'];
$_POST['height'] = $_POST['height'] * $_POST['oitar'];
}
$header = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT);
$header = apply_filters('wp_create_file_in_uploads', $header); // For replication
$parent = get_post($_POST['attachment_id']);
$parent_url = $parent->guid;
$url = str_replace(basename($parent_url), basename($header), $parent_url);
set_theme_mod('header_image', $url);
// cleanup
$file = get_attached_file( $_POST['attachment_id'] );
$medium = str_replace(basename($file), 'midsize-'.basename($file), $file);
@unlink( apply_filters( 'wp_delete_file', $medium ) );
wp_delete_attachment( $_POST['attachment_id'] );
return $this->finished();
}
示例8: set_site_icon
/**
* Saves a new Site Icon.
*
* @since 4.3.0
*/
public function set_site_icon()
{
check_admin_referer('set-site-icon');
$attachment_id = absint($_REQUEST['attachment_id']);
$create_new_attachement = !empty($_REQUEST['create-new-attachment']);
/*
* If the current attachment as been set as site icon don't delete it.
*/
if (get_option('site_icon') == $attachment_id) {
// Get the file path.
$image_url = get_attached_file($attachment_id);
// Update meta data and possibly regenerate intermediate sizes.
add_filter('intermediate_image_sizes_advanced', array($this, 'additional_sizes'));
$this->update_attachment_metadata($attachment_id, $image_url);
remove_filter('intermediate_image_sizes_advanced', array($this, 'additional_sizes'));
} else {
// Delete any existing site icon images.
$this->delete_site_icon();
if (empty($_REQUEST['skip-cropping'])) {
$cropped = wp_crop_image($attachment_id, $_REQUEST['crop-x'], $_REQUEST['crop-y'], $_REQUEST['crop-w'], $_REQUEST['crop-h'], $this->min_size, $this->min_size);
} elseif ($create_new_attachement) {
$cropped = _copy_image_file($attachment_id);
} else {
$cropped = get_attached_file($attachment_id);
}
if (!$cropped || is_wp_error($cropped)) {
wp_die(__('Image could not be processed. Please go back and try again.'), __('Image Processing Error'));
}
$object = $this->create_attachment_object($cropped, $attachment_id);
if ($create_new_attachement) {
unset($object['ID']);
}
// Update the attachment.
add_filter('intermediate_image_sizes_advanced', array($this, 'additional_sizes'));
$attachment_id = $this->insert_attachment($object, $cropped);
remove_filter('intermediate_image_sizes_advanced', array($this, 'additional_sizes'));
// Save the site_icon data into option
update_option('site_icon', $attachment_id);
}
add_settings_error('site-icon', 'icon-updated', __('Site Icon updated.'), 'updated');
}
示例9: upme_initialize_upload_box
function upme_initialize_upload_box()
{
global $current_user, $upme_save;
$id = $_GET['upme_id'];
$meta = isset($_GET['upme_meta']) ? $_GET['upme_meta'] : '';
$disabled = isset($_GET['upme_disabled']) ? $_GET['upme_disabled'] : '';
$settings = get_option('upme_options');
$display = '<html>
<head>
' . upme_crop_iframe_head() . '
<style type="text/css">
html{
overflow: hidden;
}
</style>
</head>
<body>
<form id="upme-crop-frm" action="" method="post" enctype="multipart/form-data">';
$display .= ' <div class="upme-crop-wrap">';
$display .= ' <div class="upme-wrap">';
$display .= ' <div class="upme-field upme-separator upme-edit upme-clearfix" style="display: block;">' . __('Update Profile Picture', 'upme') . '</div>';
$profile_pic_url = get_the_author_meta($meta, $id);
if (is_array($upme_save->errors) && count($upme_save->errors) != 0) {
if (($id == $current_user->ID || current_user_can('edit_users')) && is_numeric($id)) {
$display .= upme_display_upload_box($id, $meta, $disabled, $profile_pic_url, 'block');
$display .= upme_display_crop_box($id, $meta, $profile_pic_url, 'none');
}
} elseif (isset($_POST['upme-upload-submit-' . $id]) || isset($_POST['upme-crop-request-' . $id])) {
// Display crop area on file upload or crop link click
if (($id == $current_user->ID || current_user_can('edit_users')) && is_numeric($id)) {
$display .= upme_display_crop_box($id, $meta, $profile_pic_url, 'block');
}
} elseif (isset($_POST['upme-crop-submit-' . $id])) {
// Crop the image on area selection and submit
$data_x1 = isset($_POST['upme-crop-x1']) ? $_POST['upme-crop-x1'] : 0;
$data_y1 = isset($_POST['upme-crop-y1']) ? $_POST['upme-crop-y1'] : 0;
$data_width = isset($_POST['upme-crop-width']) ? $_POST['upme-crop-width'] : 50;
$data_height = isset($_POST['upme-crop-height']) ? $_POST['upme-crop-height'] : 50;
$src = get_the_author_meta($meta, $id);
$upme_upload_path = '';
$upme_upload_url = '';
if ($upload_dir = upme_get_uploads_folder_details()) {
$upme_upload_path = $upload_dir['basedir'] . "/upme/";
$upme_upload_url = $upload_dir['baseurl'] . "/upme/";
$src = str_replace($upme_upload_url, $upme_upload_path, $src);
}
if (is_readable($src)) {
$result = wp_crop_image($src, $data_x1, $data_y1, $data_width, $data_height, $data_width, $data_height);
if (!is_wp_error($result)) {
$cropped_path = str_replace($upme_upload_path, $upme_upload_url, $result);
update_user_meta($id, $meta, $cropped_path);
$display .= upme_display_upload_box($id, $meta, $disabled, $profile_pic_url, 'block');
}
}
update_crop_image_display($id, $meta, $cropped_path);
} elseif (isset($_POST['upme-crop-save-' . $id])) {
$src = get_the_author_meta($meta, $id);
update_crop_image_display($id, $meta, $src);
} else {
if (($id == $current_user->ID || current_user_can('edit_users')) && is_numeric($id)) {
$display .= upme_display_upload_box($id, $meta, $disabled, $profile_pic_url, 'block');
$display .= upme_display_crop_box($id, $meta, $profile_pic_url, 'none');
}
}
$display .= ' </div>';
$display .= ' </div>';
$display .= ' </form>
</body>
</html>';
echo $display;
exit;
}
示例10: step_3
/**
* Display third step of custom header image page.
*
* @since 2.1.0
*/
function step_3()
{
check_admin_referer('custom-header-crop-image');
if (!current_theme_supports('custom-header', 'uploads')) {
wp_die(__('Cheatin’ uh?'));
}
if (!empty($_POST['skip-cropping']) && !(current_theme_supports('custom-header', 'flex-height') || current_theme_supports('custom-header', 'flex-width'))) {
wp_die(__('Cheatin’ uh?'));
}
if ($_POST['oitar'] > 1) {
$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
$_POST['width'] = $_POST['width'] * $_POST['oitar'];
$_POST['height'] = $_POST['height'] * $_POST['oitar'];
}
$attachment_id = absint($_POST['attachment_id']);
$original = get_attached_file($attachment_id);
$max_width = 0;
// For flex, limit size of image displayed to 1500px unless theme says otherwise
if (current_theme_supports('custom-header', 'flex-width')) {
$max_width = 1500;
}
if (current_theme_supports('custom-header', 'max-width')) {
$max_width = max($max_width, get_theme_support('custom-header', 'max-width'));
}
$max_width = max($max_width, get_theme_support('custom-header', 'width'));
if (current_theme_supports('custom-header', 'flex-height') && !current_theme_supports('custom-header', 'flex-width') || $_POST['width'] > $max_width) {
$dst_height = absint($_POST['height'] * ($max_width / $_POST['width']));
} elseif (current_theme_supports('custom-header', 'flex-height') && current_theme_supports('custom-header', 'flex-width')) {
$dst_height = absint($_POST['height']);
} else {
$dst_height = get_theme_support('custom-header', 'height');
}
if (current_theme_supports('custom-header', 'flex-width') && !current_theme_supports('custom-header', 'flex-height') || $_POST['width'] > $max_width) {
$dst_width = absint($_POST['width'] * ($max_width / $_POST['width']));
} elseif (current_theme_supports('custom-header', 'flex-width') && current_theme_supports('custom-header', 'flex-height')) {
$dst_width = absint($_POST['width']);
} else {
$dst_width = get_theme_support('custom-header', 'width');
}
if (empty($_POST['skip-cropping'])) {
$cropped = wp_crop_image($attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height);
} elseif (!empty($_POST['create-new-attachment'])) {
$cropped = _copy_image_file($attachment_id);
} else {
$cropped = get_attached_file($attachment_id);
}
if (!$cropped || is_wp_error($cropped)) {
wp_die(__('Image could not be processed. Please go back and try again.'), __('Image Processing Error'));
}
/** This filter is documented in wp-admin/custom-header.php */
$cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id);
// For replication
$parent = get_post($attachment_id);
$parent_url = $parent->guid;
$url = str_replace(basename($parent_url), basename($cropped), $parent_url);
$size = @getimagesize($cropped);
$image_type = $size ? $size['mime'] : 'image/jpeg';
// Construct the object array
$object = array('ID' => $attachment_id, 'post_title' => basename($cropped), 'post_content' => $url, 'post_mime_type' => $image_type, 'guid' => $url, 'context' => 'custom-header');
if (!empty($_POST['create-new-attachment'])) {
unset($object['ID']);
}
// Update the attachment
$attachment_id = wp_insert_attachment($object, $cropped);
wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $cropped));
$width = $dst_width;
$height = $dst_height;
$this->set_header_image(compact('url', 'attachment_id', 'width', 'height'));
// cleanup
$medium = str_replace(basename($original), 'midsize-' . basename($original), $original);
if (file_exists($medium)) {
/**
* Filter the path of the file to delete.
*
* @since 2.1.0
*
* @param string $medium Path to the file to delete.
*/
@unlink(apply_filters('wp_delete_file', $medium));
}
if (empty($_POST['create-new-attachment']) && empty($_POST['skip-cropping'])) {
/** This filter is documented in wp-admin/custom-header.php */
@unlink(apply_filters('wp_delete_file', $original));
}
return $this->finished();
}
示例11: set_site_icon
/**
* Saves a new Site Icon.
*
* @since 4.3.0
*/
public function set_site_icon()
{
check_admin_referer('set-site-icon');
// Delete any existing site icon images.
$this->delete_site_icon();
$attachment_id = absint($_POST['attachment_id']);
// TODO
if (empty($_POST['skip-cropping'])) {
$crop_ratio = (double) $_POST['crop_ratio'];
$crop_data = $this->convert_coordinates_from_resized_to_full($_POST['crop-x'], $_POST['crop-y'], $_POST['crop-w'], $_POST['crop-h'], $crop_ratio);
$cropped = wp_crop_image($attachment_id, $crop_data['crop_x'], $crop_data['crop_y'], $crop_data['crop_width'], $crop_data['crop_height'], $this->min_size, $this->min_size);
} elseif (!empty($_POST['create-new-attachment'])) {
$cropped = _copy_image_file($attachment_id);
} else {
$cropped = get_attached_file($attachment_id);
}
if (!$cropped || is_wp_error($cropped)) {
wp_die(__('Image could not be processed. Please go back and try again.'), __('Image Processing Error'));
}
$object = $this->create_attachment_object($cropped, $attachment_id);
if (!empty($_POST['create-new-attachment'])) {
unset($object['ID']);
}
// Update the attachment
add_filter('intermediate_image_sizes_advanced', array($this, 'additional_sizes'));
$attachment_id = $this->insert_attachment($object, $cropped);
remove_filter('intermediate_image_sizes_advanced', array($this, 'additional_sizes'));
// Save the site_icon data into option
update_option('site_icon', $attachment_id);
add_settings_error('site-icon', 'icon-updated', __('Site Icon updated.'), 'updated');
}
示例12: bcp_core_avatar_handle_crop
//.........这里部分代码省略.........
* file.
* @type int $crop_w Crop width. Default: the global 'full' avatar width,
* as retrieved by bp_core_avatar_full_width().
* @type int $crop_h Crop height. Default: the global 'full' avatar height,
* as retrieved by bp_core_avatar_full_height().
* @type int $crop_x The horizontal starting point of the crop. Default: 0.
* @type int $crop_y The vertical starting point of the crop. Default: 0.
* }
* @return bool True on success, false on failure.
*/
function bcp_core_avatar_handle_crop($args = '')
{
$existing_avatar = '';
$coverphoto_full_width = BCP_MAX_WIDTH;
$coverphoto_full_height = BCP_MAX_HEIGHT;
$coverphoto_thumb_full_width = BCP_THUMB_MAX_WIDTH;
$coverphoto_thumb_full_height = BCP_THUMB_MAX_HEIGHT;
$r = wp_parse_args($args, array('object' => 'user', 'avatar_dir' => 'avatars', 'item_id' => false, 'original_file' => false, 'crop_w' => bp_core_avatar_full_width(), 'crop_h' => bp_core_avatar_full_height(), 'crop_x' => 0, 'crop_y' => 0));
/***
* You may want to hook into this filter if you want to override this function.
* Make sure you return false.
*/
if (!apply_filters('bp_core_pre_avatar_handle_crop', true, $r)) {
return true;
}
extract($r, EXTR_SKIP);
if (empty($original_file)) {
return false;
}
$original_file = bp_core_avatar_upload_path() . $original_file;
if (!file_exists($original_file)) {
return false;
}
if (empty($item_id)) {
$avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', dirname($original_file), $item_id, $object, $avatar_dir);
} else {
$avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', bp_core_avatar_upload_path() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir);
}
if (!file_exists($avatar_folder_dir)) {
return false;
}
require_once ABSPATH . '/wp-admin/includes/image.php';
require_once ABSPATH . '/wp-admin/includes/file.php';
// Delete the existing avatar files for the object
$args = array('object_id' => $item_id, 'type' => 'user');
//change object type to groups for groups
if ('group-avatars' == $avatar_dir) {
$args['type'] = 'groups';
}
$existing_covers = bcp_fetch_cover_photo($args);
if (!empty($existing_covers)) {
// Check that the new avatar doesn't have the same name as the
// old one before deleting
$upload_dir = wp_upload_dir();
$existing_avatar_path = str_replace($upload_dir['baseurl'], '', $existing_avatar);
$new_avatar_path = str_replace($upload_dir['basedir'], '', $original_file);
if ($existing_avatar_path !== $new_avatar_path) {
if ($handle = opendir($avatar_folder_dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$file_info = pathinfo($entry);
$file_name = $file_info['filename'];
$file_ext = $file_info['extension'];
$cover_photos = array('coverphoto-full', 'coverphoto-thumb');
if (in_array($file_name, $cover_photos)) {
// cover photo exists
$file = $avatar_folder_dir . '/' . $file_name . '.' . $file_ext;
@unlink($file);
}
}
}
// close the directory
closedir($handle);
}
}
}
// Make sure we at least have a width and height for cropping
if (empty($crop_w)) {
$crop_w = bp_core_avatar_full_width();
}
if (empty($crop_h)) {
$crop_h = bp_core_avatar_full_height();
}
// Get the file extension
$data = @getimagesize($original_file);
$ext = $data['mime'] == 'image/png' ? 'png' : 'jpg';
// Set the full and thumb filenames
$full_filename = 'coverphoto-full.' . $ext;
$thumb_filename = 'coverphoto-thumb.' . $ext;
// Crop the image
$full_cropped = wp_crop_image($original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, $coverphoto_thumb_width, $coverphoto_thumb_height, false, $avatar_folder_dir . '/' . $full_filename);
$thumb_cropped = wp_crop_image($original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, $coverphoto_thumb_full_width, $coverphoto_thumb_full_height, false, $avatar_folder_dir . '/' . $thumb_filename);
// Check for errors
if (empty($full_cropped) || empty($thumb_cropped) || is_wp_error($full_cropped) || is_wp_error($thumb_cropped)) {
return false;
}
// Remove the original
@unlink($original_file);
return true;
}
示例13: save_email_design
/**
* Save options on the VFB Pro > Email Design page
*
* @access public
* @since 2.4.3
* @return void
*/
public function save_email_design()
{
global $wpdb;
if (!isset($_REQUEST['action']) || !isset($_GET['page'])) {
return;
}
if ('vfb-email-design' !== $_GET['page']) {
return;
}
if ('email_design' !== $_REQUEST['action']) {
return;
}
$form_id = absint($_REQUEST['form_id']);
check_admin_referer('update-design-' . $form_id);
$email = unserialize($wpdb->get_var($wpdb->prepare("SELECT form_email_design FROM {$this->form_table_name} WHERE form_id = %d", $form_id)));
$header_image = !empty($email['header_image']) ? $email['header_image'] : '';
if (isset($_FILES['header_image'])) {
$value = $_FILES['header_image'];
if ($value['size'] > 0) {
// Handle the upload using WP's wp_handle_upload function. Takes the posted file and an options array
$uploaded_file = wp_handle_upload($value, array('test_form' => false));
@(list($width, $height, $type, $attr) = getimagesize($uploaded_file['file']));
if ($width == 600 && $height == 137) {
$header_image = isset($uploaded_file['file']) ? $uploaded_file['url'] : '';
} elseif ($width > 600) {
$oitar = $width / 600;
$image = wp_crop_image($uploaded_file['file'], 0, 0, $width, $height, 600, $height / $oitar, false, str_replace(basename($uploaded_file['file']), 'vfb-header-img-' . basename($uploaded_file['file']), $uploaded_file['file']));
if (is_wp_error($image)) {
wp_die(__('Image could not be processed. Please go back and try again.'), __('Image Processing Error'));
}
$header_image = str_replace(basename($uploaded_file['url']), basename($image), $uploaded_file['url']);
} else {
$dst_width = 600;
$dst_height = absint($height * (600 / $width));
$cropped = wp_crop_image($uploaded_file['file'], 0, 0, $width, $height, $dst_width, $dst_height, false, str_replace(basename($uploaded_file['file']), 'vfb-header-img-' . basename($uploaded_file['file']), $uploaded_file['file']));
if (is_wp_error($cropped)) {
wp_die(__('Image could not be processed. Please go back and try again.'), __('Image Processing Error'));
}
$header_image = str_replace(basename($uploaded_file['url']), basename($cropped), $uploaded_file['url']);
}
}
}
$email_design = array('format' => $_REQUEST['format'], 'link_love' => $_REQUEST['link_love'], 'footer_text' => $_REQUEST['footer_text'], 'background_color' => $_REQUEST['background_color'], 'header_text' => $_REQUEST['header_text'], 'header_image' => $header_image, 'header_color' => $_REQUEST['header_color'], 'header_text_color' => $_REQUEST['header_text_color'], 'fieldset_color' => $_REQUEST['fieldset_color'], 'section_color' => $_REQUEST['section_color'], 'section_text_color' => $_REQUEST['section_text_color'], 'text_color' => $_REQUEST['text_color'], 'link_color' => $_REQUEST['link_color'], 'row_color' => $_REQUEST['row_color'], 'row_alt_color' => $_REQUEST['row_alt_color'], 'border_color' => $_REQUEST['border_color'], 'footer_color' => $_REQUEST['footer_color'], 'footer_text_color' => $_REQUEST['footer_text_color'], 'font_family' => $_REQUEST['font_family'], 'header_font_size' => $_REQUEST['header_font_size'], 'fieldset_font_size' => $_REQUEST['fieldset_font_size'], 'section_font_size' => $_REQUEST['section_font_size'], 'text_font_size' => $_REQUEST['text_font_size'], 'footer_font_size' => $_REQUEST['footer_font_size']);
// Update form details
$wpdb->update($this->form_table_name, array('form_email_design' => serialize($email_design)), array('form_id' => $form_id), array('%s'), array('%d'));
}
示例14: handle_crop
public function handle_crop()
{
require_once ABSPATH . '/wp-admin/includes/image.php';
$user_id = bp_displayed_user_id();
$cover_photo = get_transient('profile_cover_photo_' . $user_id);
// Get the file extension
$data = @getimagesize($cover_photo);
$ext = $data['mime'] == 'image/png' ? 'png' : 'jpg';
$base_filename = basename($cover_photo, '.' . $ext);
// create a new filename but, if it's already been cropped, strip out the -cropped
$new_filename = str_replace('-cropped', '', $base_filename) . '-cropped.' . $ext;
$new_filepath = bp_core_avatar_upload_path() . '/cover-photo/' . $user_id . '/' . $new_filename;
$new_fileurl = bp_core_avatar_url() . '/cover-photo/' . $user_id . '/' . $new_filename;
$crop_fileurl = str_replace(trailingslashit(get_home_url()), '', bp_core_avatar_url()) . '/cover-photo/' . $user_id . '/' . $new_filename;
// delete the old cover photo if it exists
if (file_exists($new_filepath)) {
@unlink($new_filepath);
}
$cropped_header = wp_crop_image($cover_photo, $_POST['x'], $_POST['y'], $_POST['w'], $_POST['h'], $this->width, $this->height, false, $crop_fileurl);
if (!is_wp_error($cropped_header)) {
$old_file_path = get_user_meta(bp_loggedin_user_id(), 'profile_cover_photo_path', true);
if (file_exists($old_file_path)) {
@unlink($old_file_path);
}
// update with the new image and path
bp_update_user_meta(bp_loggedin_user_id(), 'profile_cover_photo', $new_fileurl);
bp_update_user_meta(bp_loggedin_user_id(), 'profile_cover_photo_path', $new_filepath);
delete_transient('is_cover_photo_uploaded_' . bp_displayed_user_id());
delete_transient('profile_cover_photo_' . bp_displayed_user_id());
}
}
示例15: step_3
function step_3()
{
//check_admin_referer('custom-header-crop-image');
if ($_POST['oitar'] > 1) {
$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
$_POST['width'] = $_POST['width'] * $_POST['oitar'];
$_POST['height'] = $_POST['height'] * $_POST['oitar'];
}
$custom = get_post_custom($_POST['banner']);
$banner_height = $custom['height'][0];
$banner_width = $custom['width'][0];
$original_id = get_attached_file($_POST['attachment_id']);
$cropped = wp_crop_image($original_id, $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], $banner_width, $banner_height);
if (is_wp_error($cropped)) {
wp_die(__('Image could not be processed. Please go back and try again.'), __('Image Processing Error'));
}
$cropped = apply_filters('wp_create_file_in_uploads', $cropped, $original_id);
// For replication
$parent = get_post($original_id);
$parent_url = $parent->guid;
$url = str_replace(basename($parent_url), basename($cropped), $parent_url);
// Construct the object array
$object = array('post_title' => basename($cropped), 'post_content' => $url, 'post_mime_type' => 'image/jpeg', 'guid' => $url);
// Update the attachment
$cropped_image = wp_insert_attachment($object, $cropped);
require_once ABSPATH . 'wp-admin/includes/image.php';
$attach_data = wp_generate_attachment_metadata($cropped_image, $cropped);
wp_update_attachment_metadata($cropped_image, $attach_data);
$cropped_image_url = wp_get_attachment_url($cropped_image);
$cropped_image_id = $cropped_image;
$sliderID = $_POST['banner'];
$url = wp_get_attachment_url($cropped_image_id);
$custom = get_post_custom($sliderID);
$banner_height = $custom['height'][0];
$banner_width = $custom['width'][0];
$alcyone_slides = $custom['slides'][0];
$i = 0;
$loop = true;
while ($loop) {
//for ($i=0;$i<10;$i++){
$i++;
if ($custom['alcyone_slide_' . $i][0] == "") {
update_post_meta($sliderID, 'alcyone_slide_' . $i, $cropped_image_id);
update_post_meta($sliderID, 'slides', $alcyone_slides + 1);
$slide_id = 'alcyone_slide_' . $i;
$loop = false;
}
}
?>
<li>
<img src="<?php
echo $url;
?>
" width="<?php
echo $prew_width;
?>
" /></br>
<input type="hidden" id="image_id" value="<?php
echo $cropped_image_id;
?>
"/>
<input type="hidden" id="slide_id" value="<?php
echo $slide_id;
?>
"/>
<input type="submit" value="" class="settings"/>
<input type="submit" value="" class="delete"/>
</li>
<?php
// cleanup
$medium = str_replace(basename($original), 'midsize-' . basename($original), $original);
@unlink(apply_filters('wp_delete_file', $medium));
@unlink(apply_filters('wp_delete_file', $original));
//return finished();
die;
}