Skip to content

Commit

Permalink
v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanMisak committed Jun 4, 2014
1 parent da264b3 commit 67039d8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.2 (not released yet)
## 0.2

Features:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A Go server for on-the-fly processing and serving of images. A self-hosted image

3. Start uploading and transforming images

This is version 0.1. All feedback welcome: hello@reshnesh.com
This is version 0.2. All feedback welcome: hello@reshnesh.com


## Installation
Expand Down
8 changes: 4 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,20 @@ func configInit(configFilePath string) error {
fontFilePath = defaultFontPath
}
if _, err := os.Stat(fontFilePath); os.IsNotExist(err) {
return fmt.Errorf("font does not exist:", fontFilePath)
return fmt.Errorf("font does not exist: %s", fontFilePath)
}
fontBytes, err := ioutil.ReadFile(fontFilePath)
if err != nil {
return fmt.Errorf("loading font failed:", err)
return fmt.Errorf("loading font failed: %s", err)
}
font, err := freetype.ParseFont(fontBytes)
if err != nil {
return fmt.Errorf("loading font failed:", err)
return fmt.Errorf("loading font failed: %s", err)
}

size, ok := text["size"].(int)
if !ok {
return fmt.Errorf("%v is not a valid size", text["size"])
return fmt.Errorf("%v is not a valid size %s", text["size"])
}
if size < 1 {
return fmt.Errorf("size needs to be at least 1")
Expand Down
16 changes: 8 additions & 8 deletions transformations.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ func (t *Transformation) createFilePath(imagePath string) (string, error) {

// Watermark
if t.watermark != nil {
hash := t.watermark.Hash()
for i, _ := range sum {
hash := t.watermark.hash()
for i := range sum {
sum[i] += hash[i]
}
}

// Texts
for _, elem := range t.texts {
hash := elem.Hash()
for i, _ := range sum {
hash := elem.hash()
for i := range sum {
sum[i] += hash[i]
}
}
Expand All @@ -82,7 +82,7 @@ func (t *Transformation) createFilePath(imagePath string) (string, error) {
return imagePath[:i] + "--" + t.params.ToString() + extraHash + "--" + imagePath[i:], nil
}

func (w *Watermark) Hash() []byte {
func (w *Watermark) hash() []byte {
h := sha1.New()

io.WriteString(h, w.imagePath)
Expand All @@ -93,7 +93,7 @@ func (w *Watermark) Hash() []byte {
return h.Sum(nil)
}

func (t *Text) Hash() []byte {
func (t *Text) hash() []byte {
h := sha1.New()
writeUint := func(i uint32) {
bs := make([]byte, 4)
Expand All @@ -116,7 +116,7 @@ func (t *Text) Hash() []byte {
return h.Sum(nil)
}

func (t *Text) GetFontMetrics(scale int) FontMetrics {
func (t *Text) getFontMetrics(scale int) FontMetrics {
// Adapted from: https://code.google.com/p/plotinum/

// Converts truetype.FUnit to float64
Expand Down Expand Up @@ -290,7 +290,7 @@ func transformCropAndResize(img image.Image, transformation *Transformation) (im
c.SetFont(text.font)
c.SetFontSize(size)

fontMetrics := text.GetFontMetrics(scale)
fontMetrics := text.getFontMetrics(scale)
width := int(c.PointToFix32(fontMetrics.width) >> 8)
height := int(c.PointToFix32(fontMetrics.height) >> 8)

Expand Down

0 comments on commit 67039d8

Please sign in to comment.