options.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. package bimg
  2. /*
  3. #cgo pkg-config: vips
  4. #include "vips/vips.h"
  5. */
  6. import "C"
  7. const (
  8. // Quality defines the default JPEG quality to be used.
  9. Quality = 80
  10. // MaxSize defines the maximum pixels width or height supported.
  11. MaxSize = 16383
  12. )
  13. // Gravity represents the image gravity value.
  14. type Gravity int
  15. const (
  16. // GravityCentre represents the centre value used for image gravity orientation.
  17. GravityCentre Gravity = iota
  18. // GravityNorth represents the north value used for image gravity orientation.
  19. GravityNorth
  20. // GravityEast represents the east value used for image gravity orientation.
  21. GravityEast
  22. // GravitySouth represents the south value used for image gravity orientation.
  23. GravitySouth
  24. // GravityWest represents the west value used for image gravity orientation.
  25. GravityWest
  26. // GravitySmart enables libvips Smart Crop algorithm for image gravity orientation.
  27. GravitySmart
  28. )
  29. // Interpolator represents the image interpolation value.
  30. type Interpolator int
  31. const (
  32. // Bicubic interpolation value.
  33. Bicubic Interpolator = iota
  34. // Bilinear interpolation value.
  35. Bilinear
  36. // Nohalo interpolation value.
  37. Nohalo
  38. )
  39. var interpolations = map[Interpolator]string{
  40. Bicubic: "bicubic",
  41. Bilinear: "bilinear",
  42. Nohalo: "nohalo",
  43. }
  44. func (i Interpolator) String() string {
  45. return interpolations[i]
  46. }
  47. // Angle represents the image rotation angle value.
  48. type Angle int
  49. const (
  50. // D0 represents the rotation angle 0 degrees.
  51. D0 Angle = 0
  52. // D45 represents the rotation angle 90 degrees.
  53. D45 Angle = 45
  54. // D90 represents the rotation angle 90 degrees.
  55. D90 Angle = 90
  56. // D135 represents the rotation angle 90 degrees.
  57. D135 Angle = 135
  58. // D180 represents the rotation angle 180 degrees.
  59. D180 Angle = 180
  60. // D235 represents the rotation angle 235 degrees.
  61. D235 Angle = 235
  62. // D270 represents the rotation angle 270 degrees.
  63. D270 Angle = 270
  64. // D315 represents the rotation angle 180 degrees.
  65. D315 Angle = 315
  66. )
  67. // Direction represents the image direction value.
  68. type Direction int
  69. const (
  70. // Horizontal represents the orizontal image direction value.
  71. Horizontal Direction = C.VIPS_DIRECTION_HORIZONTAL
  72. // Vertical represents the vertical image direction value.
  73. Vertical Direction = C.VIPS_DIRECTION_VERTICAL
  74. )
  75. // Interpretation represents the image interpretation type.
  76. // See: http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/VipsImage.html#VipsInterpretation
  77. type Interpretation int
  78. const (
  79. // InterpretationError points to the libvips interpretation error type.
  80. InterpretationError Interpretation = C.VIPS_INTERPRETATION_ERROR
  81. // InterpretationMultiband points to its libvips interpretation equivalent type.
  82. InterpretationMultiband Interpretation = C.VIPS_INTERPRETATION_MULTIBAND
  83. // InterpretationBW points to its libvips interpretation equivalent type.
  84. InterpretationBW Interpretation = C.VIPS_INTERPRETATION_B_W
  85. // InterpretationCMYK points to its libvips interpretation equivalent type.
  86. InterpretationCMYK Interpretation = C.VIPS_INTERPRETATION_CMYK
  87. // InterpretationRGB points to its libvips interpretation equivalent type.
  88. InterpretationRGB Interpretation = C.VIPS_INTERPRETATION_RGB
  89. // InterpretationSRGB points to its libvips interpretation equivalent type.
  90. InterpretationSRGB Interpretation = C.VIPS_INTERPRETATION_sRGB
  91. // InterpretationRGB16 points to its libvips interpretation equivalent type.
  92. InterpretationRGB16 Interpretation = C.VIPS_INTERPRETATION_RGB16
  93. // InterpretationGREY16 points to its libvips interpretation equivalent type.
  94. InterpretationGREY16 Interpretation = C.VIPS_INTERPRETATION_GREY16
  95. // InterpretationScRGB points to its libvips interpretation equivalent type.
  96. InterpretationScRGB Interpretation = C.VIPS_INTERPRETATION_scRGB
  97. // InterpretationLAB points to its libvips interpretation equivalent type.
  98. InterpretationLAB Interpretation = C.VIPS_INTERPRETATION_LAB
  99. // InterpretationXYZ points to its libvips interpretation equivalent type.
  100. InterpretationXYZ Interpretation = C.VIPS_INTERPRETATION_XYZ
  101. )
  102. // Extend represents the image extend mode, used when the edges
  103. // of an image are extended, you can specify how you want the extension done.
  104. // See: http://www.vips.ecs.soton.ac.uk/supported/8.4/doc/html/libvips/libvips-conversion.html#VIPS-EXTEND-BACKGROUND:CAPS
  105. type Extend int
  106. const (
  107. // ExtendBlack extend with black (all 0) pixels mode.
  108. ExtendBlack Extend = C.VIPS_EXTEND_BLACK
  109. // ExtendCopy copy the image edges.
  110. ExtendCopy Extend = C.VIPS_EXTEND_COPY
  111. // ExtendRepeat repeat the whole image.
  112. ExtendRepeat Extend = C.VIPS_EXTEND_REPEAT
  113. // ExtendMirror mirror the whole image.
  114. ExtendMirror Extend = C.VIPS_EXTEND_MIRROR
  115. // ExtendWhite extend with white (all bits set) pixels.
  116. ExtendWhite Extend = C.VIPS_EXTEND_WHITE
  117. // ExtendBackground with colour from the background property.
  118. ExtendBackground Extend = C.VIPS_EXTEND_BACKGROUND
  119. // ExtendLast extend with last pixel.
  120. ExtendLast Extend = C.VIPS_EXTEND_LAST
  121. )
  122. // WatermarkFont defines the default watermark font to be used.
  123. var WatermarkFont = "sans 10"
  124. // Color represents a traditional RGB color scheme.
  125. type Color struct {
  126. R, G, B uint8
  127. }
  128. // ColorBlack is a shortcut to black RGB color representation.
  129. var ColorBlack = Color{0, 0, 0}
  130. // Watermark represents the text-based watermark supported options.
  131. type Watermark struct {
  132. Width int
  133. DPI int
  134. Margin int
  135. Opacity float32
  136. NoReplicate bool
  137. Text string
  138. Font string
  139. Background Color
  140. }
  141. // WatermarkImage represents the image-based watermark supported options.
  142. type WatermarkImage struct {
  143. Left int
  144. Top int
  145. Buf []byte
  146. Opacity float32
  147. }
  148. // GaussianBlur represents the gaussian image transformation values.
  149. type GaussianBlur struct {
  150. Sigma float64
  151. MinAmpl float64
  152. }
  153. // Sharpen represents the image sharp transformation options.
  154. type Sharpen struct {
  155. Radius int
  156. X1 float64
  157. Y2 float64
  158. Y3 float64
  159. M1 float64
  160. M2 float64
  161. }
  162. // Options represents the supported image transformation options.
  163. type Options struct {
  164. Height int
  165. Width int
  166. AreaHeight int
  167. AreaWidth int
  168. Top int
  169. Left int
  170. Quality int
  171. Compression int
  172. Zoom int
  173. Crop bool
  174. SmartCrop bool // Deprecated
  175. Enlarge bool
  176. Embed bool
  177. Flip bool
  178. Flop bool
  179. Force bool
  180. NoAutoRotate bool
  181. NoProfile bool
  182. Interlace bool
  183. Extend Extend
  184. Rotate Angle
  185. Background Color
  186. Gravity Gravity
  187. Watermark Watermark
  188. WatermarkImage WatermarkImage
  189. Type ImageType
  190. Interpolator Interpolator
  191. Interpretation Interpretation
  192. GaussianBlur GaussianBlur
  193. Sharpen Sharpen
  194. }