wp_crop_image [ WordPress Function ]
wp_crop_image ( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Benzer Fonksiyonlar: wp_load_image, wp_restore_image, wp_stream_image, wp_save_image, _copy_image_file
Crop an Image to a given size.
Source
<?php
function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
if ( is_numeric( $src ) ) { // Handle int as attachment ID
$src_file = get_attached_file( $src );
if ( ! file_exists( $src_file ) ) {
// If the file doesn't exist, attempt a url fopen on the src link.
// This can occur with certain file replication plugins.
$post = get_post( $src );
$image_type = $post->post_mime_type;
$src = load_image_to_edit( $src, $post->post_mime_type, 'full' );
} else {
$size = @getimagesize( $src_file );
$image_type = ( $size ) ? $size['mime'] : '';
$src = wp_load_image( $src_file );
}
} else {
$size = @getimagesize( $src );
$image_type = ( $size ) ? $size['mime'] : '';
$src = wp_load_image( $src );
}
if ( ! is_resource( $src ) )
return new WP_Error( 'error_loading_image', $src, $src_file );
$dst = wp_imagecreatetruecolor( $dst_w, $dst_h );
if ( $src_abs ) {
$src_w -= $src_x;
$src_h -= $src_y;
}
if ( function_exists( 'imageantialias' ) )
imageantialias( $dst, true );
imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
imagedestroy( $src ); // Free up memory
if ( ! $dst_file )
$dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file );
if ( 'image/png' != $image_type )
$dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
// The directory containing the original file may no longer exist when
// using a replication plugin.
wp_mkdir_p( dirname( $dst_file ) );
$dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) );
if ( 'image/png' == $image_type && imagepng( $dst, $dst_file ) )
return $dst_file;
elseif ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )
return $dst_file;
else
return false;
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- wp_crop_image (WordPress Function) - WPSeek.com
WordPress lookup for wp_crop_image, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme authors.
wpseek.com - PHPXRef 0.7 : WordPress : Function Reference: wp_crop_image()
Function and Method Cross Reference. wp_crop_image(). Defined at: /wp-admin/ includes/image.php -> line 30. Referenced 2 times: ...
phpxref.ftwr.co.uk - #13411 (Add support for transparancy in wp_crop_image ...
If you want to crop an image which is transparent, e.g. PNG, the background will be black. The reason is imagejpeg(). Idea: Add a new bool parameter, if it's true ...
core.trac.wordpress.org - Custom image upload field in WordPress - Stack Overflow
function resize_author_picture($file) { $file = $_POST['file']; $dimensions = getimagesize($file); $dir = dirname($file); $crop = wp_crop_image( ...
stackoverflow.com