定制 nwtn/php-respimg 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nwtn/php-respimg

最新稳定版本:1.0.1

Composer 安装命令:

composer require nwtn/php-respimg

包简介

A responsive image workflow for optimizing and resizing your images

README 文档

README

THIS REPO IS NOT MAINTAINED

php-respimg

A responsive image workflow for optimizing and resizing your images.

See also grunt-respimg.

Full documentation available at https://rawgit.com/nwtn/php-respimg/master/docs/index.html.

Requirements/dependencies

Examples

To resize one raster image, without optimization:

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

To resize one raster image and maintain aspect ratio, without optimization:

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

To resize one raster image and maintain aspect ratio, with optimization:

$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);

To resize a directory of raster images and maintain aspect ratio, with optimization:

$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);

To resize a directory of raster images and SVGs and maintain aspect ratio, with optimization:

$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);

Release History

1.0.1

  • Library loading bug fix
  • Namespacing in README

1.0.0

  • Major refactoring
  • Image optimization
  • SVG rasterization
  • Basic (non-unit) tests

0.0.2

  • Fix a path in the test file
  • Minor colorspace change (should have no effect on output)
  • Comments and stuff

0.0.1

  • Packagist release

0.0.0

  • Super experimental pre-release. Feel free to mess about with it, but don’t expect much.

统计信息

  • 总下载量: 16.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 112
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 112
  • Watchers: 7
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-08