我尝试使用这个:

$image = new JImage();
$image->loadFile($item->logo);
$image->resize('208', '125');

$properties = JImage::getImageFileProperties($item->logo);

echo $image->toFile(JPATH_CACHE . DS . $item->logo, $properties->type);

但不工作=\有什么想法吗?

最佳答案

试试这个:

// Set the path to the file
$file = '/Absolute/Path/To/File';

// Instantiate our JImage object
$image = new JImage($file);

// Get the file's properties
$properties = JImage::getImageFileProperties($file);

// Declare the size of our new image
$width = 100;
$height = 100;

// Resize the file as a new object
$resizedImage = $image->resize($width, $height, true);

// Determine the MIME of the original file to get the proper type for output
$mime = $properties->mime;

if ($mime == 'image/jpeg')
{
    $type = IMAGETYPE_JPEG;
}
elseif ($mime == 'image/png')
{
    $type = IMAGETYPE_PNG;
}
elseif ($mime == 'image/gif')
{
    $type = IMAGETYPE_GIF;
}

// Store the resized image to a new file
$resizedImage->toFile('/Absolute/Path/To/New/File', $type);

关于image - 如何在 Joomla 中调整图像大小?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10842734/

10-17 02:58