0
votes

When you upload an image, wordpress makes thumbnails 150x150, full size, etc. Is there a way to get a full size thumbnail also. I don't want to use the original image, i need a rendered photo.

I found a code which works to make a custom size thumb, it would be perfect if i can put percentage instead of pixels. Like add_image_size( 'new-size', 90% );

if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'new-size', 600, 175, true ); //(cropped)
}
add_filter('image_size_names_choose', 'my_image_sizes');
function my_image_sizes($sizes) {
$addsizes = array(
"new-size" => __( "New Size")
);
$newsizes = array_merge($sizes, $addsizes);
return $newsizes;
}

Thank you.

1

1 Answers

0
votes

one way,

First get image size.

$data = getimagesize($image_path);
$width = $data[0];
$height = $data[1];

Get 10% width and height

$thumbWidth = $width * 10 / 100;
$thumbhHeight = $height * 10 / 100;

and use

add_image_size( 'new-size', $thumbWidth, $thumbhHeight, true );