Commit 8a6145e
Fix ValueError: image has wrong mode in thumbnail generation (#1128)
* Initial plan
* Fix ValueError: image has wrong mode in thumbnail generation
Convert images with unsupported PIL modes (P, CMYK, I, F, 1, LA, PA)
to RGB or RGBA before calling thumbnail() in get_thumbnail_bytes().
This prevents the ValueError that occurs when PIL tries to resize
images with these modes using high-quality resamplers.
Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
* Improve thumbnail tests: use 300x300 images and assert JPEG output
Use image dimensions larger than thumbnail_size (267x140) to ensure
the resize path is exercised. Assert the result is valid JPEG with
dimensions bounded by thumbnail_size.
Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
* Simplify mode normalization: single rule converting to RGB
Remove LA/PA special-casing since _get_bytes() always converts to RGB
before saving. Add comment explaining why the conversion is needed.
Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
* Extract _normalize_mode() helper and reuse in both create_thumbnail() and get_thumbnail_bytes()
Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
* Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>1 parent 594b283 commit 8a6145e
2 files changed
Lines changed: 81 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | | - | |
| 372 | + | |
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
389 | 415 | | |
390 | 416 | | |
391 | 417 | | |
| |||
418 | 444 | | |
419 | 445 | | |
420 | 446 | | |
| 447 | + | |
| 448 | + | |
421 | 449 | | |
422 | 450 | | |
423 | 451 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
463 | 463 | | |
464 | 464 | | |
465 | 465 | | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
466 | 518 | | |
467 | 519 | | |
468 | 520 | | |
| |||
0 commit comments