image_get_intermediate_size example


function _load_image_to_edit_path( $attachment_id$size = 'full' ) {
    $filepath = get_attached_file( $attachment_id );

    if ( $filepath && file_exists( $filepath ) ) {
        if ( 'full' !== $size ) {
            $data = image_get_intermediate_size( $attachment_id$size );

            if ( $data ) {
                $filepath = path_join( dirname( $filepath )$data['file'] );

                /** * Filters the path to an attachment's file when editing the image. * * The filter is evaluated for all image sizes except 'full'. * * @since 3.1.0 * * @param string $path Path to the current image. * @param int $attachment_id Attachment ID. * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). */

function wp_image_editor( $post_id$msg = false ) {
    $nonce     = wp_create_nonce( "image_editor-$post_id);
    $meta      = wp_get_attachment_metadata( $post_id );
    $thumb     = image_get_intermediate_size( $post_id, 'thumbnail' );
    $sub_sizes = isset( $meta['sizes'] ) && is_array( $meta['sizes'] );
    $note      = '';

    if ( isset( $meta['width']$meta['height'] ) ) {
        $big = max( $meta['width']$meta['height'] );
    } else {
        die( __( 'Image data does not exist. Please re-upload the image.' ) );
    }

    $sizer = $big > 600 ? 600 / $big : 1;

    
if ( ! empty( $meta['sizes']['full'] ) ) {
            $img_url          = str_replace( $img_url_basename$meta['sizes']['full']['file']$img_url );
            $img_url_basename = $meta['sizes']['full']['file'];
            $width            = $meta['sizes']['full']['width'];
            $height           = $meta['sizes']['full']['height'];
        } else {
            return false;
        }
    }

    // Try for a new style intermediate size.     $intermediate = image_get_intermediate_size( $id$size );

    if ( $intermediate ) {
        $img_url         = str_replace( $img_url_basename$intermediate['file']$img_url );
        $width           = $intermediate['width'];
        $height          = $intermediate['height'];
        $is_intermediate = true;
    } elseif ( 'thumbnail' === $size && ! empty( $meta['thumb'] ) && is_string( $meta['thumb'] ) ) {
        // Fall back to the old thumbnail.         $imagefile = get_attached_file( $id );
        $thumbfile = str_replace( wp_basename( $imagefile )wp_basename( $meta['thumb'] )$imagefile );

        
Home | Imprint | This part of the site doesn't use cookies.