avonis/php-respimg

用于优化和调整图像大小的响应式图像工作流程

2.0.1 2019-08-19 15:44 UTC

This package is not auto-updated.

Last update: 2024-09-24 16:09:32 UTC


README

https://github.com/nwtn/php-respimg分叉而来

用于优化和调整图像大小的响应式图像工作流程。

另请参阅 grunt-respimg

完整文档可在https://rawgit.com/nwtn/php-respimg/master/docs/index.html找到。

需求/依赖项

示例

调整单个光栅图像的大小,不进行优化

$image = new avonis\Respimg($input_filename);
$image->smartResize($output_width, $output_height, false);
$image->writeImage($output_filename);

调整单个光栅图像的大小并保持宽高比,不进行优化

$image = new avonis\Respimg($input_filename);
$image->smartResize($output_width, 0, false);
$image->writeImage($output_filename);

调整单个光栅图像的大小并保持宽高比,进行优化

$image = new avonis\Respimg($input_filename);
$image->smartResize($output_width, 0, true);
$image->writeImage($output_filename);
avonis\Respimg::optimize($output_filename, 0, 1, 1, 1);

调整目录中的多个光栅图像的大小并保持宽高比,进行优化

$exts = array('jpeg', 'jpg', 'png');
if ($dir = opendir($input_path)) {
	while (($file = readdir($dir)) !== false) {
		$base = pathinfo($file, PATHINFO_BASENAME);
		$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
		if (in_array($ext, $exts)) {
			$image = new avonis\Respimg($input_path . '/' . $file);
			$image->smartResize($width, 0, true);
			$image->writeImage($output_path . '/' . $base . '-w' . $w . '.' . $ext);
		}
	}
}
avonis\Respimg::optimize($output_path, 0, 1, 1, 1);

调整目录中的多个光栅图像和 SVG 图像的大小并保持宽高比,进行优化

$exts = array('jpeg', 'jpg', 'png');
if ($dir = opendir($input_path)) {
	while (($file = readdir($dir)) !== false) {
		$base = pathinfo($file, PATHINFO_BASENAME);
		$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
		if (in_array($ext, $exts)) {
			$image = new avonis\Respimg($input_path . '/' . $file);
			$image->smartResize($width, 0, true);
			$image->writeImage($output_path . '/' . $base . '-w' . $w . '.' . $ext);
		} elseif ($ext === 'svg') {
			copy($input_path . '/' . $file, $output_path . '/' . $file);
			avonis\Respimg::rasterize($input_path . '/' . $file, $output_path . '/', $width, 0);
		}
	}
}
avonis\Respimg::optimize($output_path, 3, 1, 1, 1);

发布历史

1.0.1

  • 库加载错误修复
  • README 中的命名空间

1.0.0

  • 主要重构
  • 图像优化
  • SVG 光栅化
  • 基本(非单元)测试

0.0.2

  • 修复测试文件中的路径
  • 颜色空间的小幅度更改(应不会影响输出)
  • 注释和其他内容

0.0.1

  • 包管理器发布

0.0.0

  • 超级实验性预发布版本。您可以随意尝试,但不要期待太多。