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 SLIDE_HEIGHT = 5143500
|
||||||
const HEADER_HEIGHT = 392471
|
const HEADER_HEIGHT = 392471
|
||||||
|
|
||||||
const IMAGE_WIDTH = SLIDE_WIDTH
|
|
||||||
const IMAGE_HEIGHT = SLIDE_HEIGHT - HEADER_HEIGHT
|
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>`
|
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 {
|
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)
|
return fmt.Errorf("error decoding PNG image: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var width, height, top, left int
|
var width, height int
|
||||||
srcSize := src.Bounds().Size()
|
srcSize := src.Bounds().Size()
|
||||||
|
|
||||||
// compute the size and position to fit the slide
|
// compute the size and position to fit the slide
|
||||||
if srcSize.X > srcSize.Y {
|
if srcSize.X > srcSize.Y {
|
||||||
width = IMAGE_WIDTH
|
width = IMAGE_WIDTH
|
||||||
height = int(float64(width) * (float64(srcSize.X) / float64(srcSize.Y)))
|
height = int(float64(width) * (float64(srcSize.Y) / float64(srcSize.X)))
|
||||||
left = 0
|
|
||||||
top = (IMAGE_HEIGHT - height) / 2
|
|
||||||
} else {
|
} else {
|
||||||
height = IMAGE_HEIGHT
|
height = IMAGE_HEIGHT
|
||||||
width = int(float64(height) * (float64(srcSize.X) / float64(srcSize.Y)))
|
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{
|
slide := &Slide{
|
||||||
BoardPath: make([]string, len(boardPath)),
|
BoardPath: make([]string, len(boardPath)),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue