You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "Nicola-Reseda (via GitHub)" <gi...@apache.org> on 2026/08/06 06:52:37 UTC

[I] Picture Resize fails due to error in getDimFromCell() [poi]

Nicola-Reseda opened a new issue, #1201:
URL: https://github.com/apache/poi/issues/1201

   Trying to resize a picture in a XSSF Spreadsheet but this fails consistently because the target size is computed as negative. The computation of the `picture.resize(double, double)` is done by the help of `getDimFromCell(...)` method in ImageUtils.class where the bug is located.
   I havent'checked whether this logic works for pictures spreading over several cells, but it surely fails when the picture should be within one single cell. Both the width and height computation return 0 in the best case (when no Dx/Dy is defined), negative values otherwise (which leads to subsequent IllegalArgumentException)
   
       for (int cellIdx = startCell; cellIdx<=endCell; cellIdx++) {
                   final double dim = nextSize.apply(cellIdx).doubleValue() * EMU_PER_PIXEL;
                   double leadSpace = 0;
                   if (cellIdx == startCell) {
                       //space in the leftmost cell
                       leadSpace = (hssfUnits > 0)
                           ? dim * startD/(double)hssfUnits
                           : startD;
                   }
   
                   double trailSpace = 0;
                   if (cellIdx == endCell) {
                       // space after the rightmost cell
                       trailSpace = (hssfUnits > 0)
                           ? dim * (hssfUnits-endD)/(double)hssfUnits
                           : dim - endD;
                   }
                   targetSize += dim - leadSpace - trailSpace; // --> = dim - startD - dim - endD = -startD - endD
               }
   
   The computation of trail space should not be `trailSpace = dim - endD` but rather `trailSpace = endD`
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [I] Picture Resize fails due to error in getDimFromCell() [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning closed issue #1201: Picture Resize fails due to error in getDimFromCell()
URL: https://github.com/apache/poi/issues/1201


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [I] Picture Resize fails due to error in getDimFromCell() [poi]

Posted by "adityaanikam (via GitHub)" <gi...@apache.org>.
adityaanikam commented on issue #1201:
URL: https://github.com/apache/poi/issues/1201#issuecomment-5252892071

   Confirmed the code matches your quote exactly. Worked through the math on the hssfUnits <= 0 branch myself: with trailSpace = dim - endD as it stands, targetSize comes out to endD - startD in the single cell case, not quite the -startD - endD your comment states, looks like a small slip in your own derivation there. But your fix holds up regardless: trailSpace = endD gives dim - startD - endD, which is the only version that lines up semantically with the hssfUnits > 0 branch right above it (both represent the same trailing space, just in different units). I'd like to put up that fix.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org