set_quality example


function image_resize( $file$max_w$max_h$crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
    _deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' );

    $editor = wp_get_image_editor( $file );
    if ( is_wp_error( $editor ) )
        return $editor;
    $editor->set_quality( $jpeg_quality );

    $resized = $editor->resize( $max_w$max_h$crop );
    if ( is_wp_error( $resized ) )
        return $resized;

    $dest_file = $editor->generate_filename( $suffix$dest_path );
    $saved = $editor->save( $dest_file );

    if ( is_wp_error( $saved ) )
        return $saved;

    
$this->mime_type = $this->get_mime_type( $this->image->getImageFormat() );
        } catch ( Exception $e ) {
            return new WP_Error( 'invalid_image', $e->getMessage()$this->file );
        }

        $updated_size = $this->update_size();

        if ( is_wp_error( $updated_size ) ) {
            return $updated_size;
        }

        return $this->set_quality();
    }

    /** * Sets Image Compression quality on a 1-100% scale. * * @since 3.5.0 * * @param int $quality Compression Quality. Range: [1,100] * @return true|WP_Error True if set successfully; WP_Error on failure. */
    public function set_quality( $quality = null ) {
        
return new WP_Error( 'invalid_image', __( 'Could not read image size.' )$this->file );
        }

        if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) {
            imagealphablending( $this->image, false );
            imagesavealpha( $this->image, true );
        }

        $this->update_size( $size[0]$size[1] );
        $this->mime_type = $size['mime'];

        return $this->set_quality();
    }

    /** * Sets or updates current image size. * * @since 3.5.0 * * @param int $width * @param int $height * @return true */
    


    /** * Gets the Image Compression quality on a 1-100% scale. * * @since 4.0.0 * * @return int Compression Quality. Range: [1,100] */
    public function get_quality() {
        if ( ! $this->quality ) {
            $this->set_quality();
        }

        return $this->quality;
    }

    /** * Sets Image Compression quality on a 1-100% scale. * * @since 3.5.0 * * @param int $quality Compression Quality. Range: [1,100] * @return true|WP_Error True if set successfully; WP_Error on failure. */
Home | Imprint | This part of the site doesn't use cookies.