Exemple #1
0
func (this *AmeshImageGenerator) ImageGenerate(date string, digest string) string {
	mapImage := image.ReadImageFromAsset("data/amesh_map.jpg")
	defer mapImage.Destroy()
	maskImage := image.ReadImageFromAsset("data/amesh_mask.png")
	defer maskImage.Destroy()
	rainImage := image.GetImageFromUrl("http://tokyo-ame.jwa.or.jp/mesh/100/" + date + ".gif")
	defer rainImage.Destroy()

	err := mapImage.CompositeImage(rainImage, imagick.COMPOSITE_OP_OVER, 0, 0)
	if err != nil {
		fmt.Println(err)
	}
	err = mapImage.CompositeImage(maskImage, imagick.COMPOSITE_OP_OVER, 0, 0)
	if err != nil {
		fmt.Println(err)
	}
	err = mapImage.CropImage(1300, 600, 900, 650)
	if err != nil {
		fmt.Println(err)
	}
	ihrImage := image.ReadImageFromAsset("data/ihr.png")
	defer ihrImage.Destroy()

	err = mapImage.CompositeImage(ihrImage, imagick.COMPOSITE_OP_OVER, 970, 320)
	if err != nil {
		fmt.Println(err)
	}

	url, err := image.Upload(digest+".png", mapImage.GetImageBlob())
	if err != nil {
		fmt.Println(err)
	}
	return url
}
Exemple #2
0
func (this *JmaImageGenerator) GenerateImage(date string, digest string) string {
	mapImage := image.ReadImageFromAsset("data/jma_map.png")
	defer mapImage.Destroy()
	maskImage := image.ReadImageFromAsset("data/jma_mask.png")
	defer maskImage.Destroy()
	manucipalityImage := image.ReadImageFromAsset("data/jma_manucipality.png")
	defer manucipalityImage.Destroy()
	ihrImage := image.ReadImageFromAsset("data/ihr.png")
	defer ihrImage.Destroy()

	rainImage := imagick.NewMagickWand()
	defer rainImage.Destroy()
	for w := MIN_WIDTH; w <= MAX_WIDTH; w++ {
		tmpImage := imagick.NewMagickWand()
		defer tmpImage.Destroy()
		for h := MIN_HEIGHT; h <= MAX_HEIGHT; h++ {
			tmp := image.GetImageFromUrl("http://www.jma.go.jp/jp/highresorad/highresorad_tile/HRKSNC/" + date + "/" + date + "/zoom6/" + strconv.Itoa(w) + "_" + strconv.Itoa(h) + ".png")
			defer tmp.Destroy()
			tmpImage.AddImage(tmp)
			tmpImage.SetLastIterator()
		}
		tmpImage.SetFirstIterator()
		tmpImage = tmpImage.AppendImages(true)
		rainImage.AddImage(tmpImage)
		rainImage.SetLastIterator()
	}
	rainImage.SetFirstIterator()
	rainImage = rainImage.AppendImages(false)
	rainImage.AdaptiveResizeImage(2048, 2048)

	err := mapImage.CompositeImage(rainImage, imagick.COMPOSITE_OP_OVER, 0, 0)
	if err != nil {
		log.Println(err)
	}
	err = mapImage.CompositeImage(maskImage, imagick.COMPOSITE_OP_OVER, 0, 0)
	if err != nil {
		log.Println(err)
	}
	err = mapImage.CompositeImage(manucipalityImage, imagick.COMPOSITE_OP_OVER, 0, 0)
	if err != nil {
		log.Println(err)
	}
	err = mapImage.CropImage(1000, 500, 580, 750)
	if err != nil {
		log.Println(err)
	}
	err = mapImage.CompositeImage(ihrImage, imagick.COMPOSITE_OP_OVER, 750, 300)
	if err != nil {
		log.Println(err)
	}

	url, err := image.Upload(digest+".png", mapImage.GetImageBlob())
	if err != nil {
		fmt.Println(err)
	}
	return url
}