1Gtk2::Gdk::Pixbuf(3) User Contributed Perl Documentation Gtk2::Gdk::Pixbuf(3)
2
3
4
6 Gtk2::Gdk::Pixbuf
7
9 Glib::Object
10 +----Gtk2::Gdk::Pixbuf
11
13 pixbuf = Gtk2::Gdk::Pixbuf->new ($colorspace, $has_alpha, $bits_per_sample,
14 $width, $height)
15 · $colorspace (Gtk2::Gdk::Colorspace)
16
17 · $has_alpha (boolean)
18
19 · $bits_per_sample (integer)
20
21 · $width (integer)
22
23 · $height (integer)
24
25 pixbuf = Gtk2::Gdk::Pixbuf->new_from_data ($data, $colorspace, $has_alpha,
26 $bits_per_sample, $width, $height, $rowstride)
27 · $data (scalar) packed binary pixel data, usually made with
28 pack()
29
30 · $colorspace (Gtk2::Gdk::Colorspace)
31
32 · $has_alpha (boolean) true if the image data includes an alpha
33 channel (opacity information).
34
35 · $bits_per_sample (integer)
36
37 · $width (integer) in pixels.
38
39 · $height (integer) in pixels.
40
41 · $rowstride (integer) distance in bytes between row starts;
42 usually 3*width for rgb data, 4*width if $has_alpha is true.
43
44 Creates a new Gtk2::Gdk::Pixbuf out of in-memory image data.
45 Currently only RGB images with 8 bits per sample are supported.
46
47 In C this function allows you to wrap a GdkPixbuf structure around
48 existing pixel data. In Perl, we have to use "pack" to generate a
49 scalar containing the pixel data, and pass that scalar to
50 "new_from_data", which copies the scalar to keep it around. It
51 also manages the memory automagically, so there's no need for a
52 destruction notifier function. This all means that if you change
53 your copy of the data scalar later, the pixbuf will not reflect
54 that, but because of the way perl manages string data and scalars,
55 it would be pretty fragile to do that in the first place. If you
56 need to modify a pixbuf's data after it has been created, you can
57 create new pixbufs for the changed regions and use
58 "$pixbuf->composite", or try a different approach (possibly use a
59 server-side pixmap and gdk drawing primitives, or something like
60 libart).
61
62 pixbuf = Gtk2::Gdk::Pixbuf->new_from_file ($filename)
63 · $filename (localized file name)
64
65 May croak with a Glib::Error in $@ on failure.
66
67 pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale ($filename, $width,
68 $height, $preserve_aspect_ratio)
69 · $filename (localized file name)
70
71 · $width (integer)
72
73 · $height (integer)
74
75 · $preserve_aspect_ratio (boolean)
76
77 May croak with a Glib::Error in $@ on failure.
78
79 Since: gtk+ 2.6
80
81 pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_size ($filename, $width,
82 $height)
83 · $filename (localized file name)
84
85 · $width (integer)
86
87 · $height (integer)
88
89 May croak with a Glib::Error in $@ on failure.
90
91 Since: gtk+ 2.4
92
93 pixbuf = Gtk2::Gdk::Pixbuf->new_from_inline ($data, $copy_pixels=TRUE)
94 · $data (scalar) packed binary data, the format is special, see
95 discussion
96
97 · $copy_pixels (boolean) whether $data should be copied, defaults
98 to true
99
100 Gtk+ ships with a tool called "gdk-pixbuf-csource", which turns any
101 image understood by gdk-pixbuf into the C syntax of the declaration
102 of a static data structure containing that image data, to be
103 #included directly into your source code.
104 "gdk_pixbuf_new_from_inline" creates a new GdkPixbuf from that data
105 structure.
106
107 Currently, this is not very easy to do from Perl. The output of
108 "gdk-pixbuf-csource" must be mangled rather ruthlessly to create
109 valid Perl code using pack and translation from C string escapes to
110 valid Perl string escapes (for encoding and interpretation isses).
111 Because Perl scalars are garbage collected, it's rather rare to
112 have the ability to use static data, so $copy_pixels defaults to
113 true; if you can guarantee the image data will outlive the pixbuf
114 you can pass false here and save some memory.
115
116 For more information, see the description of
117 "gdk_pixbuf_new_from_inline" in the C API reference at
118 http://gtk.org/api/ .
119
120 May croak with a Glib::Error in $@ on failure.
121
122 pixbuf = Gtk2::Gdk::Pixbuf->new_from_xpm_data (...)
123 · ... (list) xpm data as a list of strings (see discussion)
124
125 X Pixel Map (XPM) files are designed to be easy to edit and easy to
126 include directly into C programs. The file format is the C syntax
127 of the declaration and initialization of a variable containing an
128 array of strings. "new_from_xpm_data" allows you to create an
129 image from such data included directly in your program source.
130
131 Since XPM files are C syntax, you must mangle that source a bit to
132 work in a Perl program. For example, this is a valid xpm, but it
133 is not valid Perl code:
134
135 /* XPM */
136 static char * test_xpm[] = {
137 "4 4 3 1",
138 " c None",
139 ". c red",
140 "+ c blue",
141 ".. +",
142 ". ++",
143 " ++.",
144 "++.."};
145
146 You'll need to change the array declaration format, and change the
147 double-quoted strings to single-quoted to avoid Perl interpreting
148 any chars in the strings as special.
149
150 my @test_xpm = (
151 '4 4 3 1',
152 ' c None',
153 '. c red',
154 '+ c blue',
155 '.. +',
156 '. ++',
157 ' ++.',
158 '++..');
159
160 $pixbuf = Gtk2::Gdk::Pixbuf->new_from_xpm_data (@test_xpm);
161
162 [It's only two or three regexes... Perhaps we should distribute a
163 script to convert XPM files to the proper format?]
164
165 pixbuf = $src_pixbuf->new_subpixbuf ($src_x, $src_y, $width, $height)
166 · $src_x (integer)
167
168 · $src_y (integer)
169
170 · $width (integer)
171
172 · $height (integer)
173
174 pixbuf = $pixbuf->add_alpha ($substitute_color, $r, $g, $b)
175 · $substitute_color (boolean)
176
177 · $r (Glib::UChar)
178
179 · $g (Glib::UChar)
180
181 · $b (Glib::UChar)
182
183 pixbuf = $src->apply_embedded_orientation
184 Since: gtk+ 2.11
185
186 integer = $pixbuf->get_bits_per_sample
187 colorspace = $pixbuf->get_colorspace
188 $src->composite ($dest, $dest_x, $dest_y, $dest_width, $dest_height,
189 $offset_x, $offset_y, $scale_x, $scale_y, $interp_type, $overall_alpha)
190 · $dest (Gtk2::Gdk::Pixbuf)
191
192 · $dest_x (integer)
193
194 · $dest_y (integer)
195
196 · $dest_width (integer)
197
198 · $dest_height (integer)
199
200 · $offset_x (double)
201
202 · $offset_y (double)
203
204 · $scale_x (double)
205
206 · $scale_y (double)
207
208 · $interp_type (Gtk2::Gdk::InterpType)
209
210 · $overall_alpha (integer)
211
212 $src->composite_color ($dest, $dest_x, $dest_y, $dest_width, $dest_height,
213 $offset_x, $offset_y, $scale_x, $scale_y, $interp_type, $overall_alpha,
214 $check_x, $check_y, $check_size, $color1, $color2)
215 · $dest (Gtk2::Gdk::Pixbuf)
216
217 · $dest_x (integer)
218
219 · $dest_y (integer)
220
221 · $dest_width (integer)
222
223 · $dest_height (integer)
224
225 · $offset_x (double)
226
227 · $offset_y (double)
228
229 · $scale_x (double)
230
231 · $scale_y (double)
232
233 · $interp_type (Gtk2::Gdk::InterpType)
234
235 · $overall_alpha (integer)
236
237 · $check_x (integer)
238
239 · $check_y (integer)
240
241 · $check_size (integer)
242
243 · $color1 (unsigned)
244
245 · $color2 (unsigned)
246
247 pixbuf or undef = $src->composite_color_simple ($dest_width, $dest_height,
248 $interp_type, $overall_alpha, $check_size, $color1, $color2)
249 · $dest_width (integer)
250
251 · $dest_height (integer)
252
253 · $interp_type (Gtk2::Gdk::InterpType)
254
255 · $overall_alpha (integer)
256
257 · $check_size (integer)
258
259 · $color1 (unsigned)
260
261 · $color2 (unsigned)
262
263 pixbuf = $pixbuf->copy
264 $src_pixbuf->copy_area ($src_x, $src_y, $width, $height, $dest_pixbuf,
265 $dest_x, $dest_y)
266 · $src_x (integer)
267
268 · $src_y (integer)
269
270 · $width (integer)
271
272 · $height (integer)
273
274 · $dest_pixbuf (Gtk2::Gdk::Pixbuf)
275
276 · $dest_x (integer)
277
278 · $dest_y (integer)
279
280 (format, width, height) = $pixbuf->get_file_info ($filename)
281 · $filename (localized file name)
282
283 Parses enough of $filename to determine and return the format and
284 size. If the format is unknown or the file can't be opened,
285 returns an empty list.
286
287 Since: gtk+ 2.4
288
289 $pixbuf->fill ($pixel)
290 · $pixel (unsigned) a packed RGBA value.
291
292 Clear $pixbuf to contain only the value given in $pixel.
293
294 pixbuf = $src->flip ($horizontal)
295 · $horizontal (boolean)
296
297 Since: gtk+ 2.6
298
299 list = Gtk2::Gdk::Pixbuf->get_formats
300 Returns a list of hashes with information about the formats
301 supported by Gtk2::Gdk::Pixbuf.
302
303 Since: gtk+ 2.2
304
305 pixbuf = Gtk2::Gdk::Pixbuf->get_from_drawable ($src, $cmap, $src_x, $src_y,
306 $dest_x, $dest_y, $width, $height)
307 pixbuf = $pixbuf->get_from_drawable ($src, $cmap, $src_x, $src_y, $dest_x,
308 $dest_y, $width, $height)
309 · $src (Gtk2::Gdk::Drawable)
310
311 · $cmap (Gtk2::Gdk::Colormap or undef)
312
313 · $src_x (integer)
314
315 · $src_y (integer)
316
317 · $dest_x (integer)
318
319 · $dest_y (integer)
320
321 · $width (integer)
322
323 · $height (integer)
324
325 Fetch pixels from a Gtk2::Gdk::Drawable as a Gtk2::Gdk::Pixbuf.
326 Returns a new Gtk2::Gdk::Pixbuf if you use the class form, or
327 $pixbuf if you call it on an existing pixbuf.
328
329 pixbuf = Gtk2::Gdk::Pixbuf->get_from_image ($src, $cmap, $src_x, $src_y,
330 $dest_x, $dest_y, $width, $height)
331 pixbuf = $pixbuf->get_from_image ($src, $cmap, $src_x, $src_y, $dest_x,
332 $dest_y, $width, $height)
333 · $src (Gtk2::Gdk::Image)
334
335 · $cmap (Gtk2::Gdk::Colormap or undef)
336
337 · $src_x (integer)
338
339 · $src_y (integer)
340
341 · $dest_x (integer)
342
343 · $dest_y (integer)
344
345 · $width (integer)
346
347 · $height (integer)
348
349 Fetch pixels from a Gtk2::Gdk::Image as a Gtk2::Gdk::Pixbuf.
350 Returns a new Gtk2::Gdk::Pixbuf if you use the class form, or
351 $pixbuf if you call it on an existing pixbuf.
352
353 boolean = $pixbuf->get_has_alpha
354 integer = $pixbuf->get_height
355 integer = $pixbuf->get_n_channels
356 string or undef = $pixbuf->get_option ($key)
357 · $key (string)
358
359 scalar = $pixbuf->get_pixels
360 pixmap = $pixbuf->render_pixmap_and_mask ($alpha_threshold)
361 (pixmap, mask) = $pixbuf->render_pixmap_and_mask ($alpha_threshold)
362 · $alpha_threshold (integer)
363
364 pixmap = $pixbuf->render_pixmap_and_mask_for_colormap ($colormap,
365 $alpha_threshold)
366 (pixmap, mask) = $pixbuf->render_pixmap_and_mask_for_colormap ($colormap,
367 $alpha_threshold)
368 · $colormap (Gtk2::Gdk::Colormap)
369
370 · $alpha_threshold (integer)
371
372 $pixbuf->render_threshold_alpha ($bitmap, $src_x, $src_y, $dest_x, $dest_y,
373 $width, $height, $alpha_threshold)
374 · $bitmap (Gtk2::Gdk::Bitmap)
375
376 · $src_x (integer)
377
378 · $src_y (integer)
379
380 · $dest_x (integer)
381
382 · $dest_y (integer)
383
384 · $width (integer)
385
386 · $height (integer)
387
388 · $alpha_threshold (integer)
389
390 $pixbuf->render_to_drawable ($drawable, $gc, $src_x, $src_y, $dest_x,
391 $dest_y, $width, $height, $dither, $x_dither, $y_dither)
392 · $drawable (Gtk2::Gdk::Drawable)
393
394 · $gc (Gtk2::Gdk::GC)
395
396 · $src_x (integer)
397
398 · $src_y (integer)
399
400 · $dest_x (integer)
401
402 · $dest_y (integer)
403
404 · $width (integer)
405
406 · $height (integer)
407
408 · $dither (Gtk2::Gdk::RgbDither)
409
410 · $x_dither (integer)
411
412 · $y_dither (integer)
413
414 $pixbuf->render_to_drawable_alpha ($drawable, $src_x, $src_y, $dest_x,
415 $dest_y, $width, $height, $alpha_mode, $alpha_threshold, $dither,
416 $x_dither, $y_dither)
417 · $drawable (Gtk2::Gdk::Drawable)
418
419 · $src_x (integer)
420
421 · $src_y (integer)
422
423 · $dest_x (integer)
424
425 · $dest_y (integer)
426
427 · $width (integer)
428
429 · $height (integer)
430
431 · $alpha_mode (Gtk2::Gdk::PixbufAlphaMode)
432
433 · $alpha_threshold (integer)
434
435 · $dither (Gtk2::Gdk::RgbDither)
436
437 · $x_dither (integer)
438
439 · $y_dither (integer)
440
441 pixbuf = $src->rotate_simple ($angle)
442 · $angle (Gtk2::Gdk::PixbufRotation)
443
444 Since: gtk+ 2.6
445
446 integer = $pixbuf->get_rowstride
447 $src->saturate_and_pixelate ($dest, $saturation, $pixelate)
448 · $dest (Gtk2::Gdk::Pixbuf)
449
450 · $saturation (double)
451
452 · $pixelate (boolean)
453
454 $pixbuf->save ($filename, $type, ...)
455 · $filename (localized file name)
456
457 · $type (string) name of file format (e.g. "jpeg", "png")
458
459 · ... (list) list of key-value save options
460
461 Save $pixbuf to a file named $filename, in the format $type, which
462 is currently "jpeg" or "png". The function will croak if there is
463 an error, which may arise from file- or image format-related
464 issues.
465
466 Any values in ... should be key/value string pairs that modify the
467 saving parameters. For example:
468
469 $pixbuf->save ($filename, 'jpeg', quality => '100');
470
471 Currently only a few parameters exist. JPEG images can be saved
472 with a "quality" parameter; its value should be in the range
473 [0,100]. Text chunks can be attached to PNG images by specifying
474 parameters of the form "tEXt::key", where key is an ASCII string of
475 length 1-79. The values are UTF-8 encoded strings. (This is a
476 quote from the C API reference; note that the C API reference is
477 the canonical source for this information.)
478
479 May croak with a Glib::Error in $@ on failure.
480
481 scalar = $pixbuf->save_to_buffer ($type, ...)
482 · $type (string) name of file format (e.g. "jpeg", "png")
483
484 · ... (list) list of key-value save options
485
486 Save $pixbuf to a scalar buffer, in the format $type, which is
487 currently "jpeg" or "png". The function will croak if there is an
488 error, which may arise from image format-related issues.
489
490 The returned string contains binary data, which may have embedded
491 nuls. Don't try to "print" it.
492
493 See "Gtk2::Gdk::Pixbuf::save" for more details.
494
495 May croak with a Glib::Error in $@ on failure.
496
497 Since: gtk+ 2.4
498
499 $src->scale ($dest, $dest_x, $dest_y, $dest_width, $dest_height, $offset_x,
500 $offset_y, $scale_x, $scale_y, $interp_type)
501 · $dest (Gtk2::Gdk::Pixbuf)
502
503 · $dest_x (integer)
504
505 · $dest_y (integer)
506
507 · $dest_width (integer)
508
509 · $dest_height (integer)
510
511 · $offset_x (double)
512
513 · $offset_y (double)
514
515 · $scale_x (double)
516
517 · $scale_y (double)
518
519 · $interp_type (Gtk2::Gdk::InterpType)
520
521 pixbuf or undef = $src->scale_simple ($dest_width, $dest_height,
522 $interp_type)
523 · $dest_width (integer)
524
525 · $dest_height (integer)
526
527 · $interp_type (Gtk2::Gdk::InterpType)
528
529 integer = $pixbuf->get_width
531 'bits-per-sample' (integer : readable / writable / construct-only /
532 private)
533 The number of bits per sample
534
535 'colorspace' (Gtk2::Gdk::Colorspace : readable / writable / construct-
536 only / private)
537 The colorspace in which the samples are interpreted
538
539 'has-alpha' (boolean : readable / writable / construct-only / private)
540 Whether the pixbuf has an alpha channel
541
542 'height' (integer : readable / writable / construct-only / private)
543 The number of rows of the pixbuf
544
545 'n-channels' (integer : readable / writable / construct-only / private)
546 The number of samples per pixel
547
548 'pixels' (gpointer : readable / writable / construct-only / private)
549 A pointer to the pixel data of the pixbuf
550
551 'rowstride' (integer : readable / writable / construct-only / private)
552 The number of bytes between the start of a row and the start of the
553 next row
554
555 'width' (integer : readable / writable / construct-only / private)
556 The number of columns of the pixbuf
557
559 enum Gtk2::Gdk::Colorspace
560 · 'rgb' / 'GDK_COLORSPACE_RGB'
561
562 enum Gtk2::Gdk::InterpType
563 · 'nearest' / 'GDK_INTERP_NEAREST'
564
565 · 'tiles' / 'GDK_INTERP_TILES'
566
567 · 'bilinear' / 'GDK_INTERP_BILINEAR'
568
569 · 'hyper' / 'GDK_INTERP_HYPER'
570
571 enum Gtk2::Gdk::PixbufAlphaMode
572 · 'bilevel' / 'GDK_PIXBUF_ALPHA_BILEVEL'
573
574 · 'full' / 'GDK_PIXBUF_ALPHA_FULL'
575
576 enum Gtk2::Gdk::PixbufError
577 · 'corrupt-image' / 'GDK_PIXBUF_ERROR_CORRUPT_IMAGE'
578
579 · 'insufficient-memory' / 'GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY'
580
581 · 'bad-option' / 'GDK_PIXBUF_ERROR_BAD_OPTION'
582
583 · 'unknown-type' / 'GDK_PIXBUF_ERROR_UNKNOWN_TYPE'
584
585 · 'unsupported-operation' / 'GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION'
586
587 · 'failed' / 'GDK_PIXBUF_ERROR_FAILED'
588
589 enum Gtk2::Gdk::PixbufRotation
590 · 'none' / 'GDK_PIXBUF_ROTATE_NONE'
591
592 · 'counterclockwise' / 'GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE'
593
594 · 'upsidedown' / 'GDK_PIXBUF_ROTATE_UPSIDEDOWN'
595
596 · 'clockwise' / 'GDK_PIXBUF_ROTATE_CLOCKWISE'
597
598 enum Gtk2::Gdk::RgbDither
599 · 'none' / 'GDK_RGB_DITHER_NONE'
600
601 · 'normal' / 'GDK_RGB_DITHER_NORMAL'
602
603 · 'max' / 'GDK_RGB_DITHER_MAX'
604
606 Gtk2, Glib::Object
607
609 Copyright (C) 2003-2008 by the gtk2-perl team.
610
611 This software is licensed under the LGPL. See Gtk2 for a full notice.
612
613
614
615perl v5.12.0 2010-05-02 Gtk2::Gdk::Pixbuf(3)