fix image size
This commit is contained in:
parent
eb2518c0e4
commit
356ab93941
2 changed files with 7 additions and 7 deletions
|
|
@ -53,9 +53,11 @@ const SLIDE_WIDTH = 9144000
|
|||
const SLIDE_HEIGHT = 5143500
|
||||
const HEADER_HEIGHT = 392471
|
||||
|
||||
const IMAGE_WIDTH = SLIDE_WIDTH
|
||||
const IMAGE_HEIGHT = SLIDE_HEIGHT - HEADER_HEIGHT
|
||||
|
||||
// keep the right aspect ratio: SLIDE_WIDTH / SLIDE_HEIGHT = IMAGE_WIDTH / IMAGE_HEIGHT
|
||||
const IMAGE_WIDTH = IMAGE_HEIGHT * (SLIDE_WIDTH / SLIDE_HEIGHT)
|
||||
|
||||
const RELS_SLIDE_XML = `<?xml version='1.0' encoding='UTF-8' standalone='yes'?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout7.xml" /><Relationship Id="%s" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/%s.png" /></Relationships>`
|
||||
|
||||
func getRelsSlideXml(imageId string) string {
|
||||
|
|
|
|||
|
|
@ -53,21 +53,19 @@ func (p *Presentation) AddSlide(pngContent []byte, boardPath []string) error {
|
|||
return fmt.Errorf("error decoding PNG image: %v", err)
|
||||
}
|
||||
|
||||
var width, height, top, left int
|
||||
var width, height int
|
||||
srcSize := src.Bounds().Size()
|
||||
|
||||
// compute the size and position to fit the slide
|
||||
if srcSize.X > srcSize.Y {
|
||||
width = IMAGE_WIDTH
|
||||
height = int(float64(width) * (float64(srcSize.X) / float64(srcSize.Y)))
|
||||
left = 0
|
||||
top = (IMAGE_HEIGHT - height) / 2
|
||||
height = int(float64(width) * (float64(srcSize.Y) / float64(srcSize.X)))
|
||||
} else {
|
||||
height = IMAGE_HEIGHT
|
||||
width = int(float64(height) * (float64(srcSize.X) / float64(srcSize.Y)))
|
||||
top = 0
|
||||
left = (IMAGE_WIDTH - width) / 2
|
||||
}
|
||||
top := (IMAGE_HEIGHT - height) / 2
|
||||
left := (SLIDE_WIDTH - width) / 2
|
||||
|
||||
slide := &Slide{
|
||||
BoardPath: make([]string, len(boardPath)),
|
||||
|
|
|
|||
Loading…
Reference in a new issue