docx icon indicating copy to clipboard operation
docx copied to clipboard

Getting image sizes

Open vacoo opened this issue 1 year ago • 0 comments

I needed to replace the signature image on the document. And relying on the image index turned out to be extremely unreliable. They can switch places. So I did getting a map of images with their dimensions. And then you can find the desired image by its size and make a replacement

	imagesSizes := docx1.ImagesSizes()
	for key := range imagesSizes {
		if imagesSizes[key].Width == 80 && imagesSizes[key].Height == 30 {
			docx1.ReplaceImage(key, signature)
		} else if imagesSizes[key].Width == 130 && imagesSizes[key].Height == 30 {
			docx1.ReplaceImage(key, usernameSignature)
		}
	}

vacoo avatar Aug 08 '23 03:08 vacoo