Welcome! Log In Create A New Profile

Advanced

Fwd: ngx_http_image_filter_module - resize увеличение изображений

An
October 29, 2014 01:28PM
---------- Forwarded message ----------
From: An <an07d5@gmail.com>
Date: 2014-10-29 12:49 GMT+04:00
Subject: ngx_http_image_filter_module - resize увеличение изображений
To: nginx-ru@nginx.org


Очень удобно, если фильтр может увеличивать изображения. Предлагаю внести
следующие изменения.

an@an-pc:~/Desktop$ cat ngx_http_image_filter_module.diff

# HG changeset patch
# User Anton Shefer <an07d5@gmail.com>
# Date 1414566573 -14400
# Wed Oct 29 11:09:33 2014 +0400
# Node ID a499f7c603f2322950698da88213aa53fb81ad46
# Parent 87ada3ba1392fadaf4d9193b5d345c248be32f77
Image filter resize - Increase images

diff -r 87ada3ba1392 -r a499f7c603f2
src/http/modules/ngx_http_image_filter_module.c
--- a/src/http/modules/ngx_http_image_filter_module.c Mon Oct 27
14:25:56 2014 -0700
+++ b/src/http/modules/ngx_http_image_filter_module.c Wed Oct 29
11:09:33 2014 +0400
@@ -546,7 +546,8 @@
&& ctx->width <= ctx->max_width
&& ctx->height <= ctx->max_height
&& ctx->angle == 0
- && !ctx->force)
+ && !ctx->force
+ && conf->filter != NGX_HTTP_IMAGE_RESIZE)
{
return ngx_http_image_asis(r, ctx);
}
@@ -773,7 +774,8 @@
if (!ctx->force
&& ctx->angle == 0
&& (ngx_uint_t) sx <= ctx->max_width
- && (ngx_uint_t) sy <= ctx->max_height)
+ && (ngx_uint_t) sy <= ctx->max_height
+ && conf->filter != NGX_HTTP_IMAGE_RESIZE)
{
gdImageDestroy(src);
return ngx_http_image_asis(r, ctx);
@@ -809,15 +811,19 @@

if (conf->filter == NGX_HTTP_IMAGE_RESIZE) {

- if ((ngx_uint_t) dx > ctx->max_width) {
+
+ if ((int)ctx->max_width > 0 && (int)ctx->max_height > 0) {
dy = dy * ctx->max_width / dx;
- dy = dy ? dy : 1;
dx = ctx->max_width;
- }
-
- if ((ngx_uint_t) dy > ctx->max_height) {
+ if (dy > (int)ctx->max_height) {
+ dx = dx * ctx->max_height / dy;
+ dy = ctx->max_height;
+ }
+ } else if ((int)ctx->max_width > 0) {
+ dy = dy * ctx->max_width / dx;
+ dx = ctx->max_width;
+ } else if ((int)ctx->max_height > 0) {
dx = dx * ctx->max_height / dy;
- dx = dx ? dx : 1;
dy = ctx->max_height;
}
# HG changeset patch
# User Anton Shefer <an07d5@gmail.com>
# Date 1414566573 -14400
# Wed Oct 29 11:09:33 2014 +0400
# Node ID a499f7c603f2322950698da88213aa53fb81ad46
# Parent 87ada3ba1392fadaf4d9193b5d345c248be32f77
Image filter resize - Increase images

diff -r 87ada3ba1392 -r a499f7c603f2 src/http/modules/ngx_http_image_filter_module.c
--- a/src/http/modules/ngx_http_image_filter_module.c Mon Oct 27 14:25:56 2014 -0700
+++ b/src/http/modules/ngx_http_image_filter_module.c Wed Oct 29 11:09:33 2014 +0400
@@ -546,7 +546,8 @@
&& ctx->width <= ctx->max_width
&& ctx->height <= ctx->max_height
&& ctx->angle == 0
- && !ctx->force)
+ && !ctx->force
+ && conf->filter != NGX_HTTP_IMAGE_RESIZE)
{
return ngx_http_image_asis(r, ctx);
}
@@ -773,7 +774,8 @@
if (!ctx->force
&& ctx->angle == 0
&& (ngx_uint_t) sx <= ctx->max_width
- && (ngx_uint_t) sy <= ctx->max_height)
+ && (ngx_uint_t) sy <= ctx->max_height
+ && conf->filter != NGX_HTTP_IMAGE_RESIZE)
{
gdImageDestroy(src);
return ngx_http_image_asis(r, ctx);
@@ -809,15 +811,19 @@

if (conf->filter == NGX_HTTP_IMAGE_RESIZE) {

- if ((ngx_uint_t) dx > ctx->max_width) {
+
+ if ((int)ctx->max_width > 0 && (int)ctx->max_height > 0) {
dy = dy * ctx->max_width / dx;
- dy = dy ? dy : 1;
dx = ctx->max_width;
- }
-
- if ((ngx_uint_t) dy > ctx->max_height) {
+ if (dy > (int)ctx->max_height) {
+ dx = dx * ctx->max_height / dy;
+ dy = ctx->max_height;
+ }
+ } else if ((int)ctx->max_width > 0) {
+ dy = dy * ctx->max_width / dx;
+ dx = ctx->max_width;
+ } else if ((int)ctx->max_height > 0) {
dx = dx * ctx->max_height / dy;
- dx = dx ? dx : 1;
dy = ctx->max_height;
}

_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru
Subject Author Posted

Fwd: ngx_http_image_filter_module - resize увеличение изображений

An October 29, 2014 01:28PM

Re: Fwd: ngx_http_image_filter_module - resize увеличение изображений

Maxim Dounin October 29, 2014 01:58PM

Re: Fwd: ngx_http_image_filter_module - resize увеличение изображений

An October 30, 2014 03:18AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 306
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready