shop-old/libs/phImaginator/phImaginator.Resize.class.php
2026-04-20 01:03:43 +02:00

90 lines
2.0 KiB
PHP

<?php
abstract class phImaginator_Resize extends phImaginator_Universal implements phImaginator_Module {
protected static $runCollected = false;
private static $destination_width;
private static $destination_height;
public static function fitBoth($width, $height) {
self::$destination_width = $width;
self::$destination_height = $height;
self::fitImage();
}
public static function fitWidth($width) {
self::$destination_width = $width;
self::fitImage();
}
public static function fitHeight($height) {
self::$destination_height = $height;
self::fitImage();
}
private static function fitImage() {
$image_data =& parent::getCurrentResource();
$proportions = array();
if (self::$destination_width) {
$proportions[] = self::$destination_width / $image_data['width'];
}
if (self::$destination_height) {
$proportions[] = self::$destination_height / $image_data['height'];
}
$use_proportion = min($proportions);
$width = $image_data['width'] * $use_proportion;
$height = $image_data['height'] * $use_proportion;
$image = imagecreatetruecolor($width, $height);
imagealphablending($image, false);
imagesavealpha($image, true);
imagecopyresampled($image, $image_data['resource'], 0, 0, 0, 0, $width, $height, $image_data['width'], $image_data['height']);
$image_data['resource'] = $image;
$image_data['width'] = $width;
$image_data['height'] = $height;
}
public static function scale($width, $height) {
$image_data =& parent::getCurrentResource();
self::$destination_width = $width;
self::$destination_height = $height;
$image = imagecreatetruecolor(self::$destination_width, self::$destination_height);
imagealphablending($image, false);
imagesavealpha($image, true);
imagecopyresampled($image, $image_data['resource'], 0, 0, 0, 0, self::$destination_width, self::$destination_height, $image_data['width'], $image_data['height']);
$image_data['resource'] = $image;
$image_data['width'] = self::$destination_width;
$image_data['height'] = self::$destination_height;
}
}
?>