func CreateImage(source string, b []byte) *Image {
	cam := System.GetCamera(source)
	if cam.Dewarp {
		b = dewarpFisheye(b)
	}

	// image's stable ID is its hash
	potato := sha256.New()
	potato.Write(b)
	handle := hex.EncodeToString(potato.Sum(nil)[:32])

	// verify that the file doesn't somehow already exist
	diskPath := Repository.dataPath(source, fmt.Sprintf("%s.%s", handle, "jpg"))
	fi, err := os.Stat(diskPath)
	if err != nil {
		if !os.IsNotExist(err) {
			panic(err)
		}
	}
	if fi != nil {
		log.Error("Image.CreateImage", "file hash collision?! '%s'", handle)
	} else {
		// write the actual file contents under its computed name
		if err := ioutil.WriteFile(diskPath, b, 0660); err != nil {
			panic(err)
		}
	}

	stat, err := os.Stat(diskPath)
	if err != nil {
		panic(err)
	}

	return &Image{
		Handle:    handle,
		Source:    source,
		Timestamp: stat.ModTime(),
		HasVideo:  false,
	}
}
// CreateImage stores the bytes to the disk according to config & convention, and returns a handle to the
// resulting image.
CreateImage stores the bytes to the disk according to config & convention, and returns a handle to the
resulting image.
// CreateImage stores the bytes to the disk according to config & convention and returns a handle to the // resulting image .
func CreateImage(source string, b []byte) *Image {
	cam := System.GetCamera(source)
	if cam.Dewarp {
		b = dewarpFisheye(b)
	}
	potato := sha256.New()
	potato.Write(b)
	handle := hex.EncodeToString(potato.Sum(nil)[:32])
	diskPath := Repository.dataPath(source, fmt.Sprintf("%s.%s", handle, "jpg"))
	fi, err := os.Stat(diskPath)
	if err != nil {
		if !os.IsNotExist(err) {
			panic(err)
		}
	}
	if fi != nil {
		log.Error("Image.CreateImage", "file hash collision?! '%s'", handle)
	} else {
		if err := ioutil.WriteFile(diskPath, b, 0660); err != nil {
			panic(err)
		}
	}
	stat, err := os.Stat(diskPath)
	if err != nil {
		panic(err)
	}
	return &Image{
		Handle:    handle,
		Source:    source,
		Timestamp: stat.ModTime(),
		HasVideo:  false,
	}
}
func CreateImage ( source string , b [ ] byte ) * Image { cam := System . GetCamera ( source ) if cam . Dewarp { b = dewarpFisheye ( b ) } potato := sha256 . New ( ) potato . Write ( b ) handle := hex . EncodeToString ( potato . Sum ( nil ) [ : 32 ] ) diskPath := Repository . dataPath ( source , fmt . Sprintf ( " " , handle , " " ) ) fi , err := os . Stat ( diskPath ) if err != nil { if ! os . IsNotExist ( err ) { panic ( err ) } } if fi != nil { log . Error ( " " , " " , handle ) } else { if err := ioutil . WriteFile ( diskPath , b , 0660 ) ; err != nil { panic ( err ) } } stat , err := os . Stat ( diskPath ) if err != nil { panic ( err ) } return & Image { Handle : handle , Source : source , Timestamp : stat . ModTime ( ) , HasVideo : false , } }
CreateImage stores the bytes to the disk according to config & convention, and returns a handle to the
resulting image.
CreateImage stores the bytes to the disk according to config & convention and returns a handle to the resulting image .
// image's stable ID is its hash // verify that the file doesn't somehow already exist // write the actual file contents under its computed name