image_resize

Definition:
function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {}

Scale down an image to fit a particular size and save a new copy of the image.
The PNG transparency will be preserved using the function, as well as the image type. If the file going in is PNG, then the resized image is going to be PNG. The only supported image types are PNG, GIF, and JPEG.

Parameters

  • string $file: Image file path.
  • int $max_w: Maximum width to resize to.
  • int $max_h: Maximum height to resize to.
  • bool $crop: Optional. Whether to crop image or resize.
  • string $suffix: Optional. File suffix.
  • string $dest_path: Optional. New image file path.
  • int $jpeg_quality: Optional, default is 90. Image quality percentage.

Return values

returns:WP_Error on failure. String with new destination path.

Source code

function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {



	$image = wp_load_image( $file );

	if ( !is_resource( $image ) )

		return new WP_Error( 'error_loading_image', $image, $file );



	$size = @getimagesize( $file );

	if ( !$size )

		return new WP_Error('invalid_image', __('Could not read image size'), $file);

	list($orig_w, $orig_h, $orig_type) = $size;



	$dims = image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop);

	if ( !$dims )

		return new WP_Error( 'error_getting_dimensions', __('Could not calculate resized image dimensions') );

	list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;



	$newimage = wp_imagecreatetruecolor( $dst_w, $dst_h );



	imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);



	// convert from full colors to index colors, like original PNG.

	if ( IMAGETYPE_PNG == $orig_type && function_exists('imageistruecolor') && !imageistruecolor( $image ) )

		imagetruecolortopalette( $newimage, false, imagecolorstotal( $image ) );



	// we don't need the original in memory anymore

	imagedestroy( $image );



	// $suffix will be appended to the destination filename, just before the extension

	if ( !$suffix )

		$suffix = "{$dst_w}x{$dst_h}";

1999

image_media_send_to_editor

Definition:
function image_media_send_to_editor($html, $attachment_id, $attachment) {}

Parameters

  • unknown_type $html
  • unknown_type $attachment_id
  • unknown_type $attachment

Source code

function image_media_send_to_editor($html, $attachment_id, $attachment) {

	$post =& get_post($attachment_id);

	if ( substr($post->post_mime_type, 0, 5) == 'image' ) {

		$url = $attachment['url'];

		$align = !empty($attachment['align']) ? $attachment['align'] : 'none';

		$size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium';

		$alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : '';

		$rel = ( $url == get_attachment_link($attachment_id) );



		return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt);

	}



	return $html;

}

1997

image_make_intermediate_size

Definition:
function image_make_intermediate_size($file, $width, $height, $crop=false) {}

Resize an image to make a thumbnail or intermediate size.
The returned array has the file size, the image width, and image height. The filter ‘image_make_intermediate_size’ can be used to hook in and change the values of the returned array. The only parameter is the resized file path.

Parameters

  • string $file: File path.
  • int $width: Image width.
  • int $height: Image height.
  • bool $crop: Optional, default is false. Whether to crop image to specified height and width or resize.

Return values

returns:False, if no image was created. Metadata array on success.

Defined filters

  • image_make_intermediate_size
    apply_filters('image_make_intermediate_size', $resized_file)

Source code

function image_make_intermediate_size($file, $width, $height, $crop=false) {

	if ( $width || $height ) {

		$resized_file = image_resize($file, $width, $height, $crop);

		if ( !is_wp_error($resized_file) && $resized_file && $info = getimagesize($resized_file) ) {

			$resized_file = apply_filters('image_make_intermediate_size', $resized_file);

			return array(

				'file' => wp_basename( $resized_file ),

				'width' => $info[0],

				'height' => $info[1],

			);

		}

	}

	return false;

}

1995

image_link_input_fields

Definition:
function image_link_input_fields($post, $url_type = '') {}

Retrieve HTML for the Link URL buttons with the default link type as specified.

Parameters

  • unknown_type $post
  • unknown_type $url_type

Source code

function image_link_input_fields($post, $url_type = '') {



	$file = wp_get_attachment_url($post->ID);

	$link = get_attachment_link($post->ID);



	if ( empty($url_type) )

		$url_type = get_user_setting('urlbutton', 'post');



	$url = '';

	if ( $url_type == 'file' )

		$url = $file;

	elseif ( $url_type == 'post' )

		$url = $link;



	return "

	<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />

	<button type='button' class='button urlnone' title=''>" . __('None') . "</button>

	<button type='button' class='button urlfile' title='" . esc_attr($file) . "'>" . __('File URL') . "</button>

	<button type='button' class='button urlpost' title='" . esc_attr($link) . "'>" . __('Post URL') . "</button>

";

}

1993

image_hwstring

Definition:
function image_hwstring($width, $height) {}

Retrieve width and height attributes using given width and height values.
Both attributes are required in the sense that both parameters must have a value, but are optional in that if you set them to false or null, then they will not be added to the returned string.

Parameters

  • int|string $width: Optional. Width attribute value.
  • int|string $height: Optional. Height attribute value.

Return values

returns:HTML attributes for width and, or height.

Source code

function image_hwstring($width, $height) {

	$out = '';

	if ($width)

		$out .= 'width="'.intval($width).'" ';

	if ($height)

		$out .= 'height="'.intval($height).'" ';

	return $out;

}

1991