BP_GOPP_Image_Editor_GS::save( string $destfilename = null, string $mime_type = null )

Creates JPEG preview from PDF.

Description

Parameters

$destfilename

(string) (Optional)

Default value: null

$mime_type

(string) (Optional)

Default value: null

Return

(array|WP_Error) 'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string

Source

File: bp-document/classes/class-bp-gopp-image-editor-gs.php

	public function save( $destfilename = null, $mime_type = null ) {
		list( $filename, $extension, $mime_type ) = $this->get_output_format( $destfilename, $mime_type );

		if ( 'image/jpeg' !== $mime_type ) {
			return new WP_Error( 'image_save_error', __( 'Unsupported MIME type.', 'buddyboss' ), $mime_type );
		}

		if ( ! $filename || ! ( $dirname = dirname( $filename ) ) ) {
			return new WP_Error( 'image_save_error', __( 'Unsupported destination.', 'buddyboss' ), $filename );
		}

		// Make sure not to overwrite existing JPEG with same name. Redundant now for WP 4.7.3+ after #39875, but keep for BC.
		$filename = $dirname . '/' . wp_unique_filename( $dirname, wp_basename( $filename ) );

		if ( ! ( $cmd = self::gs_cmd( $this->get_gs_args( $filename ) ) ) ) {
			return new WP_Error( 'image_save_error', __( 'No Ghostscript.', 'buddyboss' ) );
		}
		$return_var = -1;
		$output     = array();
		exec( $cmd, $output, $return_var );

		if ( 0 !== $return_var ) {
			do_action( 'gopp_error', __CLASS__, __FUNCTION__, __LINE__, compact( 'cmd', 'return_var', 'output' ) );
			return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed', 'buddyboss' ) );
		}

		$size = @ getimagesize( $filename );
		if ( ! $size ) {
			return new WP_Error( 'image_save_error', __( 'Could not read image size.', 'buddyboss' ) );
		}

		// Transmogrify into the JPEG file.
		$this->file      = $filename;
		$this->mime_type = $mime_type;
		$this->update_size( $size[0], $size[1] );

		// Set correct file permissions
		$stat  = stat( dirname( $filename ) );
		$perms = $stat['mode'] & 0000666; // Same permissions as parent folder, strip off the executable bits.
		@ chmod( $filename, $perms );

		/** This filter is documented in wp-includes/class-wp-image-editor-gd.php */
		return array(
			'path'      => $filename,
			'file'      => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
			'width'     => $this->size['width'],
			'height'    => $this->size['height'],
			'mime-type' => $mime_type,
		);
	}

Changelog

Changelog
Version Description
BuddyBoss 1.4.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.