diff --git a/picture.go b/picture.go index de0d555870..094bff780f 100644 --- a/picture.go +++ b/picture.go @@ -721,8 +721,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 { @@ -733,7 +735,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 @@ -753,6 +755,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 { asp := float64(cellWidth) / width width, height = float64(cellWidth), height*asp