|
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 |
3 | 3 | @@ -10,7 +10,7 @@ |
4 | 4 | #include <ngx_http.h> |
5 | 5 |
|
|
324 | 324 | if (!ctx->force |
325 | 325 | && ctx->angle == 0 |
326 | 326 | && (ngx_uint_t) sx <= ctx->max_width |
327 | | -@@ -872,6 +1003,63 @@ |
| 327 | +@@ -872,6 +1003,65 @@ |
328 | 328 |
|
329 | 329 | transparent: |
330 | 330 |
|
|
376 | 376 | + } |
377 | 377 | + } |
378 | 378 | + |
| 379 | ++ // white background |
| 380 | ++ // gdImageFill(dst, 0, 0, gdImageColorAllocate(dst, 255, 255, 255)); |
379 | 381 | + my_resize(src, dst); |
380 | 382 | + // set the new original |
381 | 383 | + gdImageDestroy(src); |
|
388 | 390 | gdImageColorTransparent(src, -1); |
389 | 391 |
|
390 | 392 | dx = sx; |
391 | | -@@ -901,7 +1089,23 @@ |
| 393 | +@@ -901,7 +1091,23 @@ |
392 | 394 |
|
393 | 395 | resize = 0; |
394 | 396 |
|
|
413 | 415 | if ((ngx_uint_t) dx > ctx->max_width) { |
414 | 416 | dy = dy * ctx->max_width / dx; |
415 | 417 | 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 @@ |
417 | 430 | } |
418 | 431 | } |
419 | 432 |
|
|
424 | 437 |
|
425 | 438 | src = dst; |
426 | 439 |
|
427 | | -@@ -1016,8 +1222,24 @@ |
| 440 | +@@ -1016,8 +1226,24 @@ |
428 | 441 | return NULL; |
429 | 442 | } |
430 | 443 |
|
|
451 | 464 |
|
452 | 465 | ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
453 | 466 | "image crop: %d x %d @ %d x %d", |
454 | | -@@ -1048,6 +1270,7 @@ |
| 467 | +@@ -1048,6 +1274,7 @@ |
455 | 468 | } |
456 | 469 |
|
457 | 470 | gdImageInterlace(dst, (int) conf->interlace); |
458 | 471 | + ngx_http_image_watermark(r, conf, dst); |
459 | 472 |
|
460 | 473 | out = ngx_http_image_out(r, ctx->type, dst, &size); |
461 | 474 |
|
462 | | -@@ -1122,6 +1345,20 @@ |
| 475 | +@@ -1122,6 +1349,20 @@ |
463 | 476 | #endif |
464 | 477 | break; |
465 | 478 |
|
|
480 | 493 | default: |
481 | 494 | failed = "unknown image type"; |
482 | 495 | break; |
483 | | -@@ -1171,14 +1408,37 @@ |
| 496 | +@@ -1171,14 +1412,37 @@ |
484 | 497 | u_char *out; |
485 | 498 | ngx_int_t q; |
486 | 499 | ngx_http_image_filter_conf_t *conf; |
|
520 | 533 | q = ngx_http_image_filter_get_value(r, conf->jqcv, conf->jpeg_quality); |
521 | 534 | if (q <= 0) { |
522 | 535 | return NULL; |
523 | | -@@ -1195,13 +1455,11 @@ |
| 536 | +@@ -1195,13 +1459,11 @@ |
524 | 537 |
|
525 | 538 | case NGX_HTTP_IMAGE_PNG: |
526 | 539 | out = gdImagePngPtr(img, size); |
|
535 | 548 | q = ngx_http_image_filter_get_value(r, conf->wqcv, conf->webp_quality); |
536 | 549 | if (q <= 0) { |
537 | 550 | return NULL; |
538 | | -@@ -1214,6 +1472,22 @@ |
| 551 | +@@ -1214,6 +1476,22 @@ |
539 | 552 | #endif |
540 | 553 | break; |
541 | 554 |
|
|
558 | 571 | default: |
559 | 572 | failed = "unknown image type"; |
560 | 573 | break; |
561 | | -@@ -1263,7 +1537,27 @@ |
| 574 | +@@ -1263,7 +1541,27 @@ |
562 | 575 |
|
563 | 576 | n = ngx_atoi(value->data, value->len); |
564 | 577 |
|
|
587 | 600 | return (ngx_uint_t) n; |
588 | 601 | } |
589 | 602 |
|
590 | | -@@ -1299,9 +1593,13 @@ |
| 603 | +@@ -1299,9 +1597,13 @@ |
591 | 604 | conf->jpeg_quality = NGX_CONF_UNSET_UINT; |
592 | 605 | conf->webp_quality = NGX_CONF_UNSET_UINT; |
593 | 606 | conf->sharpen = NGX_CONF_UNSET_UINT; |
|
601 | 614 |
|
602 | 615 | return conf; |
603 | 616 | } |
604 | | -@@ -1364,6 +1662,37 @@ |
| 617 | +@@ -1364,6 +1666,37 @@ |
605 | 618 | ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, |
606 | 619 | 1 * 1024 * 1024); |
607 | 620 |
|
|
639 | 652 | return NGX_CONF_OK; |
640 | 653 | } |
641 | 654 |
|
642 | | -@@ -1662,6 +1991,66 @@ |
| 655 | +@@ -1662,6 +1995,66 @@ |
643 | 656 | } |
644 | 657 |
|
645 | 658 |
|
|
706 | 719 | static ngx_int_t |
707 | 720 | ngx_http_image_filter_init(ngx_conf_t *cf) |
708 | 721 | { |
709 | | -@@ -1673,3 +2062,109 @@ |
| 722 | +@@ -1673,3 +2066,113 @@ |
710 | 723 |
|
711 | 724 | return NGX_OK; |
712 | 725 | } |
|
785 | 798 | + offset = (int)((requestedLength - calculatedLength) / 2); |
786 | 799 | + } |
787 | 800 | + |
| 801 | ++ if (offset < 0) { |
| 802 | ++ offset = 0; |
| 803 | ++ } |
| 804 | ++ |
788 | 805 | + return (offset); |
789 | 806 | +} |
790 | 807 | + |
|
797 | 814 | + int destinationY = destination->sy; |
798 | 815 | + |
799 | 816 | + if (destinationRatio > originalRatio) { |
800 | | -+ destinationX = floor(destination->sy * originalRatio); |
| 817 | ++ destinationX = ceil(destination->sy * originalRatio); |
801 | 818 | + } |
802 | 819 | + else { |
803 | | -+ destinationY = floor(destination->sx / originalRatio); |
| 820 | ++ destinationY = ceil(destination->sx / originalRatio); |
804 | 821 | + } |
805 | 822 | + |
806 | 823 | + gdImageCopyResampled( |
|
0 commit comments