diff --git a/picture.go b/picture.go index 5f7a7d3c53..c6c8c2bd8f 100644 --- a/picture.go +++ b/picture.go @@ -740,8 +740,10 @@ func (f *File) drawingsWriter() { }) } -// drawingResize calculate the height and width after resizing. -func (f *File) drawingResize(sheet, cell string, width, height float64, opts *GraphicOptions) (w, h, c, r int, err error) { +// GetCellPixelsWithCoordinates returns the pixel dimensions of a specified cell within a given sheet, +// accounting for merged cells. This function calculates the total pixel width and height +// for individual or merged cells and provides the column and row index of the cell. +func (f *File) GetCellPixelsWithCoordinates(sheet, cell string) (cellWidth, cellHeight, c, r int, err error) { var mergeCells []MergeCell mergeCells, err = f.GetMergeCells(sheet) if err != nil { @@ -752,7 +754,7 @@ func (f *File) drawingResize(sheet, cell string, width, height float64, opts *Gr if c, r, err = CellNameToCoordinates(cell); err != nil { return } - cellWidth, cellHeight := f.getColWidth(sheet, c), f.getRowHeight(sheet, r) + cellWidth, cellHeight = f.getColWidth(sheet, c), f.getRowHeight(sheet, r) for _, mergeCell := range mergeCells { if inMergeCell { continue @@ -772,6 +774,12 @@ func (f *File) drawingResize(sheet, cell string, width, height float64, opts *Gr cellHeight += f.getRowHeight(sheet, row) } } + return +} + +// drawingResize calculate the height and width after resizing. +func (f *File) drawingResize(sheet, cell string, width, height float64, opts *GraphicOptions) (w, h, c, r int, err error) { + cellWidth, cellHeight, c, r, err := f.GetCellPixelsWithCoordinates(sheet, cell) if float64(cellWidth) < width || float64(cellHeight) < height { aspWidth := float64(cellWidth) / width aspHeight := float64(cellHeight) / height