示例#1
0
文件: imshell.go 项目: rskull/Imshell
func Convert(imagePath, replaceText string, width float64) (string, error) {
	var buffer string

	imtext := NewImageText(replaceText)

	imagick.Initialize()
	defer imagick.Terminate()

	originalImage := imagick.NewMagickWand()
	defer originalImage.Destroy()

	err := originalImage.ReadImage(imagePath)
	if err != nil {
		return "", fmt.Errorf("invalid parameter not image file: %s", imagePath)
	}

	originWidth := float64(originalImage.GetImageWidth())
	originHeight := float64(originalImage.GetImageHeight())

	height := math.Floor(width / originWidth * originHeight)

	// resize
	if err := originalImage.ScaleImage(uint(width), uint(height)); err != nil {
		return "", fmt.Errorf("invalid parameter width: %s", width)
	}

	iterator := originalImage.NewPixelIterator()
	defer iterator.Destroy()

	for y := 0; y < int(height); y++ {

		pixels := iterator.GetNextIteratorRow()
		if len(pixels) == 0 {
			break
		}

		for _, pixel := range pixels {
			if !pixel.IsVerified() {
				return "", fmt.Errorf("convert error: %s", "unverified pixel")
			}
			r := (uint8)(255 * pixel.GetRed())
			g := (uint8)(255 * pixel.GetGreen())
			b := (uint8)(255 * pixel.GetBlue())
			short := RGBToShort(r, g, b)

			if replaceText == "" {
				buffer += fmt.Sprintf("\x1b[48;05;%sm  \x1b[0m", short)
			} else {
				buffer += fmt.Sprintf("\x1b[38;05;%sm%s\x1b[0m", short, imtext.GetText())
			}
		}
		buffer += "\n"

		if err := iterator.SyncIterator(); err != nil {
			return "", fmt.Errorf("convert error: %s", err)
		}
	}

	return buffer, nil
}
示例#2
0
文件: main.go 项目: phzfi/RIC
func main() {

	cpath := flag.String("c", "config.ini", "Sets the configuration .ini file used.")
	flag.Parse()
	// CLI arguments

	conf := config.ReadConfig(*cpath)

	mem := flag.Uint64("m", conf.Server.Memory, "Sets the maximum memory to be used for caching images in bytes. Does not account for memory consumption of other things.")
	imagick.Initialize()
	defer imagick.Terminate()

	log.Println("Server starting...")
	logging.Debug("Debug enabled")

	server, handler, ln := NewServer(8005, *mem, conf)
	handler.started = time.Now()
	err := server.Serve(ln)
	end := time.Now()

	// Get number of requests
	requests := strconv.FormatUint((*handler).requests, 10)

	// Calculate the elapsed time
	duration := end.Sub(handler.started)
	log.Println("Server requests: " + requests)
	log.Println("Server uptime: " + duration.String())

	// Log errors
	if err != nil {
		log.Fatal(err)
	}
}
示例#3
0
文件: image.go 项目: phzfi/RIC
func init() {
	imagick.Initialize()
}
示例#4
0
func run() error {
	imagick.Initialize()

	engine = qml.NewEngine()
	QML = &qmlVar{}
	engine.Context().SetVar("go", QML)
	findfonts()
	engine.AddImageProvider("images", imgProvider)
	path = "qrc:///qml"

	mainQml, err = engine.LoadFile(path + "/main.qml")
	if err != nil {
		return err
	}

	edtQml, err = engine.LoadFile(path + "/qml/songEdit.qml")
	if err != nil {
		return err
	}

	cellQml, err = engine.LoadFile(path + "/qml/cell.qml")
	if err != nil {
		return err
	}

	qimg, err = engine.LoadFile(path + "/qml/img.qml")
	if err != nil {
		return err
	}

	qlst, err := engine.LoadFile(path + "/lst/tst.qml")
	if err != nil {
		return err
	}

	qlstEle, err := engine.LoadFile(path + "/lst/lstEle.qml")
	if err != nil {
		return err
	}

	window = mainQml.CreateWindow(engine.Context())
	window2 = edtQml.CreateWindow(engine.Context())

	textEdit = window.ObjectByName("textEdit")
	//signals for whole qml
	setSignals()
	slides.add()

	//var from GO to qml

	//image is ready for imageprovider
	imgready = true
	tstlst := qlst.Create(engine.Context())
	tstlst.Set("parent", window.ObjectByName("data1"))
	tstLlst := qlstEle.Create(engine.Context())
	tstLlst.Call("get1")
	//fmt.Println(tstLlst.Property("id1"))
	tstlst.Call("addLst") //.Call("get1")  //).(qml.Object).Create(engine.Context()).Set("parent", qlst.ObjectByName("nestedModel"))
	window.Show()
	window2.Show()
	edtQmlShow()
	slides[0].clearcache()
	qml.RunMain(glInit)

	window.Wait()

	imagick.Terminate()
	return nil
}