-
Notifications
You must be signed in to change notification settings - Fork 181
/
magick_wand_prop.go
476 lines (415 loc) · 15.9 KB
/
magick_wand_prop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
// Copyright 2013 Herbert G. Fischer. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package imagick
/*
#include <wand/MagickWand.h>
*/
import "C"
import (
//"fmt"
"errors"
"unsafe"
)
// This method deletes a wand artifact
func (mw *MagickWand) DeleteImageArtifact(artifact string) error {
csartifact := C.CString(artifact)
defer C.free(unsafe.Pointer(csartifact))
ok := C.MagickDeleteImageArtifact(mw.mw, csartifact)
return mw.getLastErrorIfFailed(ok)
}
// This method deletes a image property
func (mw *MagickWand) DeleteImageProperty(property string) error {
csproperty := C.CString(property)
defer C.free(unsafe.Pointer(csproperty))
ok := C.MagickDeleteImageProperty(mw.mw, csproperty)
return mw.getLastErrorIfFailed(ok)
}
// This method deletes a wand option
func (mw *MagickWand) DeleteOption(option string) error {
csoption := C.CString(option)
defer C.free(unsafe.Pointer(csoption))
ok := C.MagickDeleteOption(mw.mw, csoption)
return mw.getLastErrorIfFailed(ok)
}
// Returns the antialias property associated with the wand
func (mw *MagickWand) GetAntialias() bool {
return 1 == C.int(C.MagickGetAntialias(mw.mw))
}
// Returns the wand background color
func (mw *MagickWand) GetBackgroundColor() *PixelWand {
return newPixelWand(C.MagickGetBackgroundColor(mw.mw))
}
// Returns the wand colorspace type
func (mw *MagickWand) GetColorspace() ColorspaceType {
ccst := C.MagickGetColorspace(mw.mw)
return ColorspaceType(ccst)
}
// Gets the wand compression type.
func (mw *MagickWand) GetCompression() CompressionType {
return CompressionType(C.MagickGetCompression(mw.mw))
}
// Gets the wand compression quality.
func (mw *MagickWand) GetCompressionQuality() uint {
return uint(C.MagickGetCompressionQuality(mw.mw))
}
// Returns the filename associated with an image sequence.
func (mw *MagickWand) GetFilename() string {
cstr := C.MagickGetFilename(mw.mw)
defer C.free(unsafe.Pointer(cstr))
return C.GoString(cstr)
}
// Returns the font associated with the MagickWand.
func (mw *MagickWand) GetFont() string {
cstr := C.MagickGetFont(mw.mw)
defer relinquishMemory(unsafe.Pointer(cstr))
return C.GoString(cstr)
}
// Returns the format of the magick wand.
func (mw *MagickWand) GetFormat() string {
cstr := C.MagickGetFormat(mw.mw)
defer relinquishMemory(unsafe.Pointer(cstr))
return C.GoString(cstr)
}
// Gets the wand gravity.
func (mw *MagickWand) GetGravity() GravityType {
return GravityType(C.MagickGetGravity(mw.mw))
}
// Returns a value associated with the specified artifact.
func (mw *MagickWand) GetImageArtifact(artifact string) string {
csartifact := C.CString(artifact)
defer C.free(unsafe.Pointer(csartifact))
cstr := C.MagickGetImageArtifact(mw.mw, csartifact)
defer C.free(unsafe.Pointer(cstr))
return C.GoString(cstr)
}
// Returns all the artifact names that match the specified pattern associated
// with a wand. Use GetImageProperty() to return the value of a particular
// artifact.
func (mw *MagickWand) GetImageArtifacts(pattern string) (artifacts []string) {
cspattern := C.CString(pattern)
defer C.free(unsafe.Pointer(cspattern))
num := C.size_t(0)
p := C.MagickGetImageArtifacts(mw.mw, cspattern, &num)
defer relinquishMemoryCStringArray(p)
artifacts = sizedCStringArrayToStringSlice(p, num)
return
}
// Returns the named image profile.
//
// name: Name of profile to return: ICC, IPTC, or generic profile.
func (mw *MagickWand) GetImageProfile(name string) string {
csname := C.CString(name)
defer C.free(unsafe.Pointer(csname))
szlen := C.size_t(0)
csprofile := C.MagickGetImageProfile(mw.mw, csname, &szlen)
defer relinquishMemory(unsafe.Pointer(csprofile))
return C.GoStringN((*C.char)((unsafe.Pointer)(csprofile)), C.int(szlen))
}
// Returns all the profile names that match the specified pattern associated
// with a wand. Use GetImageProfile() to return the value of a particular
// property.
func (mw *MagickWand) GetImageProfiles(pattern string) (profiles []string) {
cspattern := C.CString(pattern)
defer C.free(unsafe.Pointer(cspattern))
np := C.size_t(0)
ps := C.MagickGetImageProfiles(mw.mw, cspattern, &np)
defer relinquishMemoryCStringArray(ps)
profiles = sizedCStringArrayToStringSlice(ps, np)
return
}
// Returns a value associated with the specified property.
func (mw *MagickWand) GetImageProperty(property string) string {
csproperty := C.CString(property)
defer C.free(unsafe.Pointer(csproperty))
cspv := C.MagickGetImageProperty(mw.mw, csproperty)
defer relinquishMemory(unsafe.Pointer(cspv))
return C.GoString(cspv)
}
// Returns all the property names that match the specified pattern associated
// with a wand. Use GetImageProperty() to return the value of a particular
// property.
func (mw *MagickWand) GetImageProperties(pattern string) (properties []string) {
cspattern := C.CString(pattern)
defer C.free(unsafe.Pointer(cspattern))
np := C.size_t(0)
ps := C.MagickGetImageProperties(mw.mw, cspattern, &np)
defer relinquishMemoryCStringArray(ps)
properties = sizedCStringArrayToStringSlice(ps, np)
return
}
// Gets the wand interlace scheme.
func (mw *MagickWand) GetInterlaceScheme() InterlaceType {
return InterlaceType(C.MagickGetInterlaceScheme(mw.mw))
}
// Gets the wand compression.
func (mw *MagickWand) GetInterpolateMethod() InterpolatePixelMethod {
return InterpolatePixelMethod(C.MagickGetInterpolateMethod(mw.mw))
}
// Returns a value associated with a wand and the specified key.
func (mw *MagickWand) GetOption(key string) string {
cskey := C.CString(key)
defer C.free(unsafe.Pointer(cskey))
csval := C.MagickGetOption(mw.mw, cskey)
defer relinquishMemory(unsafe.Pointer(csval))
return C.GoString(csval)
}
// Returns all the option names that match the specified pattern associated
// with a wand. Use GetOption() to return the value of a particular option.
func (mw *MagickWand) GetOptions(pattern string) (options []string) {
cspattern := C.CString(pattern)
defer C.free(unsafe.Pointer(cspattern))
np := C.size_t(0)
ps := C.MagickGetOptions(mw.mw, cspattern, &np)
defer relinquishMemoryCStringArray(ps)
options = sizedCStringArrayToStringSlice(ps, np)
return
}
// Gets the wand orientation type.
func (mw *MagickWand) GetOrientation() OrientationType {
return OrientationType(C.MagickGetOrientation(mw.mw))
}
// Returns the page geometry associated with the magick wand.
func (mw *MagickWand) GetPage() (width, height uint, x, y int, err error) {
var cw, ch C.size_t
var cx, cy C.ssize_t
ok := C.MagickGetPage(mw.mw, &cw, &ch, &cx, &cy)
width, height, x, y = uint(cw), uint(ch), int(cx), int(cy)
err = mw.getLastErrorIfFailed(ok)
return
}
// Returns the font pointsize associated with the MagickWand.
func (mw *MagickWand) GetPointsize() float64 {
return float64(C.MagickGetPointsize(mw.mw))
}
// Gets the image X and Y resolution.
func (mw *MagickWand) GetResolution() (x, y float64, err error) {
ok := C.MagickGetResolution(mw.mw, (*C.double)(&x), (*C.double)(&y))
err = mw.getLastErrorIfFailed(ok)
return
}
// Gets the horizontal and vertical sampling factor.
func (mw *MagickWand) GetSamplingFactors() (factors []float64) {
num := C.size_t(0)
pd := C.MagickGetSamplingFactors(mw.mw, &num)
factors = sizedDoubleArrayToFloat64Slice(pd, num)
return
}
// Returns the size associated with the magick wand.
func (mw *MagickWand) GetSize() (cols, rows uint, err error) {
var cc, cr C.size_t
ok := C.MagickGetSize(mw.mw, &cc, &cr)
cols, rows, err = uint(cc), uint(cr), mw.getLastErrorIfFailed(ok)
return
}
// Returns the size offset associated with the magick wand.
func (mw *MagickWand) GetSizeOffset() (offset int, err error) {
var co C.ssize_t
ok := C.MagickGetSizeOffset(mw.mw, &co)
offset, err = int(co), mw.getLastErrorIfFailed(ok)
return
}
// Returns the wand type.
func (mw *MagickWand) GetType() ImageType {
return ImageType(C.MagickGetType(mw.mw))
}
// Adds or removes a ICC, IPTC, or generic profile from an image. If the
// profile is empty, it is removed from the image otherwise added. Use a name
// of '*' and an empty profile to remove all profiles from the image.
//
// name: Name of profile to add or remove: ICC, IPTC, or generic profile.
//
func (mw *MagickWand) ProfileImage(name string, profile []byte) error {
if len(profile) == 0 {
return errors.New("zero-length profile not permitted")
}
csname := C.CString(name)
defer C.free(unsafe.Pointer(csname))
ok := C.MagickProfileImage(mw.mw, csname, unsafe.Pointer(&profile[0]), C.size_t(len(profile)))
return mw.getLastErrorIfFailed(ok)
}
// Removes the named image profile and returns it.
//
// name: name of profile to return: ICC, IPTC, or generic profile.
//
func (mw *MagickWand) RemoveImageProfile(name string) []byte {
csname := C.CString(name)
defer C.free(unsafe.Pointer(csname))
clen := C.size_t(0)
profile := C.MagickRemoveImageProfile(mw.mw, csname, &clen)
defer relinquishMemory(unsafe.Pointer(profile))
return C.GoBytes(unsafe.Pointer(profile), C.int(clen))
}
// Sets the antialias propery of the wand.
func (mw *MagickWand) SetAntialias(antialias bool) error {
ok := C.MagickSetAntialias(mw.mw, b2i(antialias))
return mw.getLastErrorIfFailed(ok)
}
// Sets the wand background color.
func (mw *MagickWand) SetBackgroundColor(background *PixelWand) error {
ok := C.MagickSetBackgroundColor(mw.mw, background.pw)
return mw.getLastErrorIfFailed(ok)
}
// Sets the wand colorspace type.
func (mw *MagickWand) SetColorspace(colorspace ColorspaceType) error {
ok := C.MagickSetColorspace(mw.mw, C.ColorspaceType(colorspace))
return mw.getLastErrorIfFailed(ok)
}
// Sets the wand compression type.
func (mw *MagickWand) SetCompression(compression CompressionType) error {
ok := C.MagickSetCompression(mw.mw, C.CompressionType(compression))
return mw.getLastErrorIfFailed(ok)
}
// Sets the wand compression quality.
func (mw *MagickWand) SetCompressionQuality(quality uint) error {
ok := C.MagickSetCompressionQuality(mw.mw, C.size_t(quality))
return mw.getLastErrorIfFailed(ok)
}
// Sets the wand pixel depth.
func (mw *MagickWand) SetDepth(depth uint) error {
ok := C.MagickSetDepth(mw.mw, C.size_t(depth))
return mw.getLastErrorIfFailed(ok)
}
// Sets the extract geometry before you read or write an image file. Use it for
// inline cropping (e.g. 200x200+0+0) or resizing (e.g.200x200).
func (mw *MagickWand) SetExtract(geometry string) error {
csgeometry := C.CString(geometry)
defer C.free(unsafe.Pointer(csgeometry))
ok := C.MagickSetExtract(mw.mw, csgeometry)
return mw.getLastErrorIfFailed(ok)
}
// Sets the filename before you read or write an image file.
func (mw *MagickWand) SetFilename(filename string) error {
csfilename := C.CString(filename)
defer C.free(unsafe.Pointer(csfilename))
ok := C.MagickSetFilename(mw.mw, csfilename)
return mw.getLastErrorIfFailed(ok)
}
// Sets the font associated with the MagickWand.
func (mw *MagickWand) SetFont(font string) error {
csfont := C.CString(font)
defer C.free(unsafe.Pointer(csfont))
ok := C.MagickSetFont(mw.mw, csfont)
return mw.getLastErrorIfFailed(ok)
}
// Sets the format of the magick wand.
func (mw *MagickWand) SetFormat(format string) error {
csformat := C.CString(format)
defer C.free(unsafe.Pointer(csformat))
ok := C.MagickSetFormat(mw.mw, csformat)
return mw.getLastErrorIfFailed(ok)
}
// Sets the gravity type.
func (mw *MagickWand) SetGravity(gtype GravityType) error {
ok := C.MagickSetGravity(mw.mw, C.GravityType(gtype))
return mw.getLastErrorIfFailed(ok)
}
// Associates a artifact with an image.
func (mw *MagickWand) SetImageArtifact(artifact, value string) error {
csartifact := C.CString(artifact)
defer C.free(unsafe.Pointer(csartifact))
csvalue := C.CString(value)
defer C.free(unsafe.Pointer(csvalue))
ok := C.MagickSetImageArtifact(mw.mw, csartifact, csvalue)
return mw.getLastErrorIfFailed(ok)
}
// Adds a named profile to the magick wand. If a profile with the same name
// already exists, it is replaced. This method differs from the ProfileImage()
// method in that it does not apply any CMS color profiles.
//
// name: Name of profile to add or remove: ICC, IPTC, or generic profile.
func (mw *MagickWand) SetImageProfile(name string, profile []byte) error {
if len(profile) == 0 {
return errors.New("zero-length profile not permitted")
}
csname := C.CString(name)
defer C.free(unsafe.Pointer(csname))
ok := C.MagickSetImageProfile(mw.mw, csname, unsafe.Pointer(&profile[0]), C.size_t(len(profile)))
return mw.getLastErrorIfFailed(ok)
}
// Associates a property with an image.
func (mw *MagickWand) SetImageProperty(property, value string) error {
csproperty := C.CString(property)
defer C.free(unsafe.Pointer(csproperty))
csvalue := C.CString(value)
defer C.free(unsafe.Pointer(csvalue))
ok := C.MagickSetImageProperty(mw.mw, csproperty, csvalue)
return mw.getLastErrorIfFailed(ok)
}
// Sets the image interlacing scheme
func (mw *MagickWand) SetInterlaceScheme(scheme InterlaceType) error {
ok := C.MagickSetInterlaceScheme(mw.mw, C.InterlaceType(scheme))
return mw.getLastErrorIfFailed(ok)
}
// Sets the interpolate pixel method.
func (mw *MagickWand) SetInterpolateMethod(method InterpolatePixelMethod) error {
ok := C.MagickSetInterpolateMethod(mw.mw, C.InterpolatePixelMethod(method))
return mw.getLastErrorIfFailed(ok)
}
// Associates one or options with the wand (.e.g
// SetOption(wand, "jpeg:perserve", "yes")).
func (mw *MagickWand) SetOption(key, value string) error {
cskey := C.CString(key)
defer C.free(unsafe.Pointer(cskey))
csvalue := C.CString(value)
defer C.free(unsafe.Pointer(csvalue))
ok := C.MagickSetOption(mw.mw, cskey, csvalue)
return mw.getLastErrorIfFailed(ok)
}
// Sets the wand orientation type.
func (mw *MagickWand) SetOrientation(orientation OrientationType) error {
ok := C.MagickSetOrientation(mw.mw, C.OrientationType(orientation))
return mw.getLastErrorIfFailed(ok)
}
// Sets the page geometry of the magick wand.
func (mw *MagickWand) SetPage(width, height uint, x, y int) error {
ok := C.MagickSetPage(mw.mw, C.size_t(width), C.size_t(height), C.ssize_t(x), C.ssize_t(y))
return mw.getLastErrorIfFailed(ok)
}
// Sets the passphrase.
func (mw *MagickWand) SetPassphrase(passphrase string) error {
cspassphrase := C.CString(passphrase)
defer C.free(unsafe.Pointer(cspassphrase))
ok := C.MagickSetPassphrase(mw.mw, cspassphrase)
return mw.getLastErrorIfFailed(ok)
}
// Sets the font pointsize associated with the MagickWand.
func (mw *MagickWand) SetPointsize(pointSize float64) error {
ok := C.MagickSetPointsize(mw.mw, C.double(pointSize))
return mw.getLastErrorIfFailed(ok)
}
// Sets the limit for a particular resource in megabytes.
func (mw *MagickWand) SetResourceLimit(rtype ResourceType, limit int64) error {
ok := C.MagickSetResourceLimit(C.ResourceType(rtype), C.MagickSizeType(limit))
return mw.getLastErrorIfFailed(ok)
}
// Sets the image resolution.
func (mw *MagickWand) SetResolution(xRes, yRes float64) error {
ok := C.MagickSetResolution(mw.mw, C.double(xRes), C.double(yRes))
return mw.getLastErrorIfFailed(ok)
}
// Sets the image sampling factors.
//
// samplingFactors: An array of floats representing the sampling factor for
// each color component (in RGB order).
func (mw *MagickWand) SetSamplingFactors(samplingFactors []float64) error {
ok := C.MagickSetSamplingFactors(mw.mw, C.size_t(len(samplingFactors)), (*C.double)(&samplingFactors[0]))
return mw.getLastErrorIfFailed(ok)
}
// Sets the size of the magick wand. Set it before you read a raw image format
// such as RGB, GRAY, or CMYK.
func (mw *MagickWand) SetSize(cols, rows uint) error {
ok := C.MagickSetSize(mw.mw, C.size_t(cols), C.size_t(rows))
return mw.getLastErrorIfFailed(ok)
}
// Sets the size and offset of the magick wand. Set it before you read a raw
// image format such as RGB, GRAY, or CMYK.
func (mw *MagickWand) SetSizeOffset(cols, rows uint, offset int) error {
ok := C.MagickSetSizeOffset(mw.mw, C.size_t(cols), C.size_t(rows), C.ssize_t(offset))
return mw.getLastErrorIfFailed(ok)
}
// Sets the image type attribute.
func (mw *MagickWand) SetType(itype ImageType) error {
ok := C.MagickSetType(mw.mw, C.ImageType(itype))
return mw.getLastErrorIfFailed(ok)
}