generate_filename example


    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 );
        }

        try {
            // Store initial format.             $orig_format = $this->image->getImageFormat();

            $this->image->setImageFormat( strtoupper( $this->get_extension( $mime_type ) ) );
        } catch ( Exception $e ) {
            return new WP_Error( 'image_save_error', $e->getMessage()$filename );
        }

        
_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;

    return $dest_file;
}

/** * Retrieve a single post, based on post ID. * * Has categories in 'post_category' property or key. Has tags in 'tags_input' * property or key. * * @since 1.0.0 * @deprecated 3.5.0 Use get_post() * @see get_post() * * @param int $postid Post ID. * @param string $mode How to return result, either OBJECT, ARRAY_N, or ARRAY_A. * @return WP_Post|null Post object or array holding post contents and information */

    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 );
        }

        if ( 'image/gif' === $mime_type ) {
            if ( ! $this->make_image( $filename, 'imagegif', array( $image$filename ) ) ) {
                return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
            }
        } elseif ( 'image/png' === $mime_type ) {
            // Convert from full colors to index colors, like original PNG.             if ( function_exists( 'imageistruecolor' ) && ! imageistruecolor( $image ) ) {
                imagetruecolortopalette( $image, false, imagecolorstotal( $image ) );
            }

            
// If there is EXIF data, rotate according to EXIF Orientation.             if ( ! is_wp_error( $resized ) && is_array( $exif_meta ) ) {
                $resized = $editor->maybe_exif_rotate();
                $rotated = $resized;
            }

            if ( ! is_wp_error( $resized ) ) {
                /* * Append "-scaled" to the image file name. It will look like "my_image-scaled.jpg". * This doesn't affect the sub-sizes names as they are generated from the original image (for best quality). */
                $saved = $editor->save( $editor->generate_filename( 'scaled' ) );

                if ( ! is_wp_error( $saved ) ) {
                    $image_meta = _wp_image_meta_replace_original( $saved$file$image_meta$attachment_id );

                    // If the image was rotated update the stored EXIF data.                     if ( true === $rotated && ! empty( $image_meta['image_meta']['orientation'] ) ) {
                        $image_meta['image_meta']['orientation'] = 1;
                    }
                } else {
                    // TODO: Log errors.                 }
            }
Home | Imprint | This part of the site doesn't use cookies.