nwtn/php-respimg

此包已被废弃,不再维护。未建议替代包。

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

1.0.1 2015-04-22 20:41 UTC

This package is not auto-updated.

Last update: 2020-01-24 15:34:54 UTC


README

此仓库未维护

php-respimg

为优化和调整图像大小提供响应式图像工作流程。

另请参阅 grunt-respimg

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

需求/依赖

示例

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

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

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

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

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

$image = new nwtn\Respimg($input_filename);
$image->smartResize($output_width, 0, true);
$image->writeImage($output_filename);
nwtn\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 nwtn\Respimg($input_path . '/' . $file);
			$image->smartResize($width, 0, true);
			$image->writeImage($output_path . '/' . $base . '-w' . $w . '.' . $ext);
		}
	}
}
nwtn\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 nwtn\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);
			nwtn\Respimg::rasterize($input_path . '/' . $file, $output_path . '/', $width, 0);
		}
	}
}
nwtn\Respimg::optimize($output_path, 3, 1, 1, 1);

发布历史

1.0.1

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

1.0.0

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

0.0.2

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

0.0.1

  • Packagist发布

0.0.0

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