PHP图像通过拉伸调整为精确的256 x 256像素

I want to resize an image to exactly 256 x 256 pixels.

I'm currently using...

$image_p = imagecreatetruecolor($imgMaxWidth, $imgMaxHeight);
imagecopyresampled($image_p, $source, 0, 0, 0, 0, $imgMaxWidth, $imgMaxHeight, $imgWidth, $imgHeight);

It only accepts Maximum Width and Maximum Height.

If I upload 615 x 339 pixels image, I will get an image resized to 256 x 141 pixels.

Can you help me?

I don't know what are you doing but your code should works

I've tried this and it works:

<?php
// The file
$filename = 'test.jpg';
$source = imagecreatefromjpeg($filename);

// Set your height and width
$imgMaxWidth = 256;
$imgMaxHeight = 256;

// Content type
header('Content-Type: image/jpeg');

// Get new dimensions
list($imgWidth, $imgHeight) = getimagesize($filename);

// This is the code you post
$image = imagecreatetruecolor($imgMaxWidth, $imgMaxHeight);
imagecopyresampled($image, $source, 0, 0, 0, 0, $imgMaxWidth, $imgMaxHeight, $imgWidth, $imgHeight);

// Output
imagejpeg($image, null, 100);
?>