Skip to content

Commit b9376ec

Browse files
committed
fix black edge line issue when image is smaller
1 parent 675901e commit b9376ec

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Nginx module - https://github.com/niiknow/docker-nginx-image-proxy/blob/master/b
77

88
Original File - https://github.com/niiknow/docker-nginx-image-proxy/blob/master/build/src/http/modules/ngx_http_image_filter_module.c
99

10-
Patch creation: `diff -u src/http/modules/ngx_http_image_filter_module.c ngx_http_image_filter_module.c > image_filter.patch`
10+
Patch creation: `diff -u build/src/http/modules/ngx_http_image_filter_module.c build/ngx_http_image_filter_module.c > build/image_filter.patch`
1111

1212
Patch apply with: `patch src/http/modules/ngx_http_image_filter_module.c image_filter.patch`
1313

build/image_filter.patch

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
--- src/http/modules/ngx_http_image_filter_module.c 2019-09-24 15:35:32.000000000 -0500
2-
+++ ngx_http_image_filter_module.c 2019-09-24 15:38:46.000000000 -0500
1+
--- build/src/http/modules/ngx_http_image_filter_module.c 2019-09-24 15:35:32.000000000 -0500
2+
+++ build/ngx_http_image_filter_module.c 2022-01-11 12:32:00.000000000 -0600
33
@@ -10,7 +10,7 @@
44
#include <ngx_http.h>
55

@@ -324,7 +324,7 @@
324324
if (!ctx->force
325325
&& ctx->angle == 0
326326
&& (ngx_uint_t) sx <= ctx->max_width
327-
@@ -872,6 +1003,63 @@
327+
@@ -872,6 +1003,65 @@
328328

329329
transparent:
330330

@@ -376,6 +376,8 @@
376376
+ }
377377
+ }
378378
+
379+
+ // white background
380+
+ // gdImageFill(dst, 0, 0, gdImageColorAllocate(dst, 255, 255, 255));
379381
+ my_resize(src, dst);
380382
+ // set the new original
381383
+ gdImageDestroy(src);
@@ -388,7 +390,7 @@
388390
gdImageColorTransparent(src, -1);
389391

390392
dx = sx;
391-
@@ -901,7 +1089,23 @@
393+
@@ -901,7 +1091,23 @@
392394

393395
resize = 0;
394396

@@ -413,7 +415,18 @@
413415
if ((ngx_uint_t) dx > ctx->max_width) {
414416
dy = dy * ctx->max_width / dx;
415417
dy = dy ? dy : 1;
416-
@@ -989,7 +1193,9 @@
418+
@@ -931,7 +1137,9 @@
419+
gdImageAlphaBlending(dst, 0);
420+
}
421+
422+
- gdImageCopyResampled(dst, src, 0, 0, 0, 0, dx, dy, sx, sy);
423+
+ // gdImageFill(dst, 0, 0, gdImageColorAllocate(dst, 255, 255, 255));
424+
+
425+
+ gdImageCopyResampled(dst, src, 0, 0, 0, 0, ceil(dx), ceil(dy), sx, sy);
426+
427+
if (colors) {
428+
gdImageTrueColorToPalette(dst, 1, 256);
429+
@@ -989,7 +1197,9 @@
417430
}
418431
}
419432

@@ -424,7 +437,7 @@
424437

425438
src = dst;
426439

427-
@@ -1016,8 +1222,24 @@
440+
@@ -1016,8 +1226,24 @@
428441
return NULL;
429442
}
430443

@@ -451,15 +464,15 @@
451464

452465
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
453466
"image crop: %d x %d @ %d x %d",
454-
@@ -1048,6 +1270,7 @@
467+
@@ -1048,6 +1274,7 @@
455468
}
456469

457470
gdImageInterlace(dst, (int) conf->interlace);
458471
+ ngx_http_image_watermark(r, conf, dst);
459472

460473
out = ngx_http_image_out(r, ctx->type, dst, &size);
461474

462-
@@ -1122,6 +1345,20 @@
475+
@@ -1122,6 +1349,20 @@
463476
#endif
464477
break;
465478

@@ -480,7 +493,7 @@
480493
default:
481494
failed = "unknown image type";
482495
break;
483-
@@ -1171,14 +1408,37 @@
496+
@@ -1171,14 +1412,37 @@
484497
u_char *out;
485498
ngx_int_t q;
486499
ngx_http_image_filter_conf_t *conf;
@@ -520,7 +533,7 @@
520533
q = ngx_http_image_filter_get_value(r, conf->jqcv, conf->jpeg_quality);
521534
if (q <= 0) {
522535
return NULL;
523-
@@ -1195,13 +1455,11 @@
536+
@@ -1195,13 +1459,11 @@
524537

525538
case NGX_HTTP_IMAGE_PNG:
526539
out = gdImagePngPtr(img, size);
@@ -535,7 +548,7 @@
535548
q = ngx_http_image_filter_get_value(r, conf->wqcv, conf->webp_quality);
536549
if (q <= 0) {
537550
return NULL;
538-
@@ -1214,6 +1472,22 @@
551+
@@ -1214,6 +1476,22 @@
539552
#endif
540553
break;
541554

@@ -558,7 +571,7 @@
558571
default:
559572
failed = "unknown image type";
560573
break;
561-
@@ -1263,7 +1537,27 @@
574+
@@ -1263,7 +1541,27 @@
562575

563576
n = ngx_atoi(value->data, value->len);
564577

@@ -587,7 +600,7 @@
587600
return (ngx_uint_t) n;
588601
}
589602

590-
@@ -1299,9 +1593,13 @@
603+
@@ -1299,9 +1597,13 @@
591604
conf->jpeg_quality = NGX_CONF_UNSET_UINT;
592605
conf->webp_quality = NGX_CONF_UNSET_UINT;
593606
conf->sharpen = NGX_CONF_UNSET_UINT;
@@ -601,7 +614,7 @@
601614

602615
return conf;
603616
}
604-
@@ -1364,6 +1662,37 @@
617+
@@ -1364,6 +1666,37 @@
605618
ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
606619
1 * 1024 * 1024);
607620

@@ -639,7 +652,7 @@
639652
return NGX_CONF_OK;
640653
}
641654

642-
@@ -1662,6 +1991,66 @@
655+
@@ -1662,6 +1995,66 @@
643656
}
644657

645658

@@ -706,7 +719,7 @@
706719
static ngx_int_t
707720
ngx_http_image_filter_init(ngx_conf_t *cf)
708721
{
709-
@@ -1673,3 +2062,109 @@
722+
@@ -1673,3 +2066,113 @@
710723

711724
return NGX_OK;
712725
}
@@ -785,6 +798,10 @@
785798
+ offset = (int)((requestedLength - calculatedLength) / 2);
786799
+ }
787800
+
801+
+ if (offset < 0) {
802+
+ offset = 0;
803+
+ }
804+
+
788805
+ return (offset);
789806
+}
790807
+
@@ -797,10 +814,10 @@
797814
+ int destinationY = destination->sy;
798815
+
799816
+ if (destinationRatio > originalRatio) {
800-
+ destinationX = floor(destination->sy * originalRatio);
817+
+ destinationX = ceil(destination->sy * originalRatio);
801818
+ }
802819
+ else {
803-
+ destinationY = floor(destination->sx / originalRatio);
820+
+ destinationY = ceil(destination->sx / originalRatio);
804821
+ }
805822
+
806823
+ gdImageCopyResampled(

build/ngx_http_image_filter_module.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,8 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
10511051
}
10521052
}
10531053

1054+
// white background
1055+
// gdImageFill(dst, 0, 0, gdImageColorAllocate(dst, 255, 255, 255));
10541056
my_resize(src, dst);
10551057
// set the new original
10561058
gdImageDestroy(src);
@@ -1135,7 +1137,9 @@ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
11351137
gdImageAlphaBlending(dst, 0);
11361138
}
11371139

1138-
gdImageCopyResampled(dst, src, 0, 0, 0, 0, dx, dy, sx, sy);
1140+
// gdImageFill(dst, 0, 0, gdImageColorAllocate(dst, 255, 255, 255));
1141+
1142+
gdImageCopyResampled(dst, src, 0, 0, 0, 0, ceil(dx), ceil(dy), sx, sy);
11391143

11401144
if (colors) {
11411145
gdImageTrueColorToPalette(dst, 1, 256);
@@ -2137,6 +2141,10 @@ static int my_offset(int calculatedLength, int requestedLength) {
21372141
offset = (int)((requestedLength - calculatedLength) / 2);
21382142
}
21392143

2144+
if (offset < 0) {
2145+
offset = 0;
2146+
}
2147+
21402148
return (offset);
21412149
}
21422150

@@ -2149,10 +2157,10 @@ static void my_resize (gdImagePtr original, gdImagePtr destination) {
21492157
int destinationY = destination->sy;
21502158

21512159
if (destinationRatio > originalRatio) {
2152-
destinationX = floor(destination->sy * originalRatio);
2160+
destinationX = ceil(destination->sy * originalRatio);
21532161
}
21542162
else {
2155-
destinationY = floor(destination->sx / originalRatio);
2163+
destinationY = ceil(destination->sx / originalRatio);
21562164
}
21572165

21582166
gdImageCopyResampled(

files/root/bin/my-startup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@ fi
2626
echo "*** Running cron"
2727
cron
2828

29+
# now=$(date +"%T")
30+
# echo "Current time : $now"
31+
32+
ls -la /root/bin
33+
2934
echo "*** Running nginx"
3035
exec /usr/sbin/nginx -g "daemon off;"

0 commit comments

Comments
 (0)