summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/draw.php69
-rw-r--r--examples/flip.php91
-rw-r--r--examples/gradtest.php57
-rw-r--r--examples/imlib_ext_filters.php17
-rw-r--r--examples/imlib_filter.php58
-rw-r--r--examples/pstext.php10
-rw-r--r--examples/scale.php30
-rw-r--r--examples/test.jpgbin0 -> 16921 bytes
-rw-r--r--examples/text.php17
9 files changed, 349 insertions, 0 deletions
diff --git a/examples/draw.php b/examples/draw.php
new file mode 100644
index 0000000..f9469e2
--- /dev/null
+++ b/examples/draw.php
@@ -0,0 +1,69 @@
+<?php
+
+/*
+ * This example draws a variety of shapes on an otherwise black image.
+ * Demonstrates draw/filled rectangles, polygins, cliprects, ellipses, etc.
+ */
+
+require './class.ImlibImage.php';
+require './class.ImlibColor.php';
+require './class.ImlibText.php';
+require './class.ImlibCliprect.php';
+require './class.ImlibDraw.php';
+require './class.ImlibPoly.php';
+
+$im = new ImlibImage();
+$im->create(225,260);
+
+$outlinecolor = Array(255,0,0,255);
+$color = Array(255,127,0,255);
+
+$box = new ImlibDraw();
+$box->set_image($im->get_id());
+$box->set_color_array($outlinecolor);
+$box->draw_rectangle(7,7,106,56);
+$box->set_color_array($color);
+$box->fill_rectangle(10,10,100,50);
+
+$poly = new ImlibPoly();
+$poly->new_poly();
+$poly->set_image($im->get_id());
+$poly->set_color(255,0,255,255);
+$poly->add_point(100,100);
+$poly->add_point(215,110);
+$poly->add_point(150,215);
+$poly->add_point(102,255);
+
+// The cliprect will leave a gap in the middle of this polygon
+$poly->set_cliprect(100,50,125,110); // Draw the top
+$poly->draw();
+$poly->set_cliprect(100,190,125,70); // Draw the bottom
+$poly->draw();
+$poly->free();
+
+$poly->set_cliprect(0,0,0,0); // Turns off the clipping rectangle
+$poly->new_poly();
+$poly->set_color(255,255,255,255);
+$poly->add_point(106,106);
+$poly->add_point(205,115);
+$poly->add_point(147,211);
+$poly->add_point(106,245);
+
+$poly->draw();
+$poly->free();
+
+// This will draw a few pseudo-randomly colored ellipses
+$j = 30;
+for ($i = 90; $i < 260; $i += 20)
+{
+ $box->set_color($i,$i*2,255-$i*2,255);
+ $box->draw_ellipse($j,$i,10,$j/2);
+ $j += 20;
+ if ($j > 70)
+ $j = 25;
+}
+
+$im->save('./draw.png');
+$im->free();
+
+?>
diff --git a/examples/flip.php b/examples/flip.php
new file mode 100644
index 0000000..2f6b3c6
--- /dev/null
+++ b/examples/flip.php
@@ -0,0 +1,91 @@
+<?php
+
+/*
+ * This example takes a source image and outputs an image with four
+ * scaled copies of the image. The original, and the image flipped
+ * using the three flip functions: horizontal, vertical, and diagonal.
+ *
+ * The images are labeled using the ImlibText class, and a background
+ * is filled behind them using a filled rectangle from the ImlibDraw class.
+ */
+
+require './class.ImlibImage.php';
+require './class.ImlibColor.php';
+require './class.ImlibCliprect.php';
+require './class.ImlibDraw.php';
+require './class.ImlibText.php';
+
+$padding = 20;
+$thumbw = 170;
+$thumbh = ''; // If this is left blank, the height will be calculated
+$bgarray = Array(220,115,115,255);
+$textarray = Array(255,255,255,255);
+$srcname = './lain-closetheworld.png';
+
+// $mode can be 'horizontal', 'vertical', or 'diagonal'
+function flipCreate($obj,$mode)
+{
+ $cb = "flip_$mode";
+ $obj->$cb();
+ $new = $obj->create_clone();
+ $obj->$cb();
+ return $new;
+}
+
+$im = new ImlibImage();
+$im->load($srcname);
+$orig = $im->create_scaled($thumbw,$thumbh);
+$im->free();
+$imw = $orig->get_width();
+$imh = $orig->get_height();
+
+// Create the image large enough to fit four scaled copies of $srcname
+$dst = new ImlibImage();
+$dst->create(2*$imw + 3*$padding, 2*$imh + 5*$padding);
+
+// Load in a font and set the color and image to draw on
+$txt = new ImlibText();
+$txt->set_color_array($textarray);
+$txt->set_image($dst->get_id());
+$txt->load('','./ARIAL',16);
+
+// Get a drawing object and set its color and image to draw on
+$box = new ImlibDraw();
+$box->set_color_array($bgarray);
+$box->set_image($dst->get_id());
+
+$orig_alpha = $orig->has_alpha();
+$box->fill_rectangle($padding-3,$padding-3, $imw+6,$imh+6);
+$txt->draw($padding,$padding+$imh,'Original');
+$orig->blend_onto_image($dst->get_id(),0,0,$orig_alpha,$imw,$imh,
+ $padding,$padding, $imw,$imh,0,$orig_alpha,0);
+
+$horiz = flipCreate($orig,'horizontal');
+$horiz_alpha = $horiz->has_alpha();
+$box->fill_rectangle(2*$padding-3+$imw,$padding-3, $imw+6,$imh+6);
+$txt->draw(2*$padding+$imw,$padding+$imh,'Horizontal');
+$horiz->blend_onto_image($dst->get_id(),0,0,$horiz_alpha,$imw,$imh,
+ 2*$padding+$imw,$padding, $imw,$imh,0,$horiz_alpha,0);
+
+$vert = flipCreate($orig,'vertical');
+$vert_alpha = $vert->has_alpha();
+$box->fill_rectangle($padding-3,3*$padding-3+$imh, $imw+6,$imh+6);
+$txt->draw($padding,3*$padding+2*$imh,'Vertical');
+$vert->blend_onto_image($dst->get_id(),0,0,$vert_alpha,$imw,$imh,$padding,
+ 3*$padding+$imh,$imw,$imh,0,$vert_alpha,0);
+
+// In order to keep things simple, this image will be cropped off if it's
+// not square. This is done to keep things simple. To show the whole
+// diagonally cropped image, the dimensions for $dst would need to be
+// calculated from the resulting height of the diagonal version of the image
+$diag = flipCreate($orig,'diagonal');
+$diag_alpha = $diag->has_alpha();
+$box->fill_rectangle(2*$padding-3+$imw,3*$padding-3+$imh, $imw+6,$imh+6);
+$txt->draw(2*$padding+$imw,3*$padding+2*$imh,'Diagonal');
+$diag->blend_onto_image($dst->get_id(),0,0,$diag_alpha,$imw,$imh,2*$padding+$imw,
+ 3*$padding+$imh,$imw,$imh,0,$diag_alpha,0);
+
+$dst->save('./flip.png');
+$dst->free();
+
+?>
diff --git a/examples/gradtest.php b/examples/gradtest.php
new file mode 100644
index 0000000..a05b259
--- /dev/null
+++ b/examples/gradtest.php
@@ -0,0 +1,57 @@
+<?php
+
+/*
+ * This example is mostly for playing with color ranges (gradients)
+ * and alpha channels.
+ */
+
+require './package.Imlib.php';
+
+$red = Array(255,35,35,255);
+$blue = Array(35,65,255,255);
+$text = Array(200,220,255,255);
+$shadow = Array(10,10,10,100);
+
+// Create objects
+$im = new ImlibImage;
+$cr = new ImlibColorRange;
+$d = new ImlibDraw;
+$t = new ImlibText;
+
+// Set up objects
+$im->create(250,150);
+$cr->create();
+$cr->set_image($im->get_id());
+$d->set_image($im->get_id());
+$t->set_image($im->get_id());
+$t->load('','banco.ttf','25');
+
+// Large blue rectangle and gradient
+$d->set_color(22,28,235,255);
+$d->fill_rectangle(10,10,210,110);
+$cr->add_color_array(0, $red);
+$cr->add_color(0,0,225,225,255);
+$cr->add_color_array(0, $blue);
+$cr->fill_rectangle(15,15,200,100,125);
+
+// Text with semitransparent shadow
+$t->set_color_array($shadow);
+$t->draw(43,48,'Showing off.');
+$t->set_color_array($text);
+$t->draw(40,45,'Showing off.');
+
+// Purple semitransparent square
+$d->set_color(195,105,195,127);
+$d->fill_rectangle(30,90,50,50);
+
+// Green-to-transparent gradient square
+$cr->free();
+$cr->create();
+$cr->add_color(0,0,255,0,0);
+$cr->add_color(0,0,255,0,50);
+$cr->add_color(0,0,255,0,255);
+$cr->fill_rectangle(90,90,50,50,235);
+
+$im->save('testgrad.png',50);
+
+?>
diff --git a/examples/imlib_ext_filters.php b/examples/imlib_ext_filters.php
new file mode 100644
index 0000000..1b785bc
--- /dev/null
+++ b/examples/imlib_ext_filters.php
@@ -0,0 +1,17 @@
+<?php
+
+$im = imlib_load_image('test.jpg');
+$im2 = imlib_clone_image($im);
+
+imlib_apply_filter($im2,"colormod",array('contrast'=>2));
+imlib_apply_filter($im,"bump_map_point",array('map'=>$im2,'depth'=>500,'x'=>100,'y'=>200,'z'=>20));
+imlib_apply_filter($im,"colormod",array('brightness'=>0.3));
+imlib_apply_filter($im,"php_tint",array('red'=>255,'green'=>0,'blue'=>0,'alpha'=>40));
+
+Header('Content-type: image/jpeg');
+
+imlib_dump_image($im);
+imlib_free_image($im);
+imlib_free_image($im2);
+
+?>
diff --git a/examples/imlib_filter.php b/examples/imlib_filter.php
new file mode 100644
index 0000000..6bda8c5
--- /dev/null
+++ b/examples/imlib_filter.php
@@ -0,0 +1,58 @@
+<?php
+
+function relief($im)
+{
+ $filter=imlib_create_filter();
+
+ imlib_filter_set_red ($filter, -1, -1, 0, -1, -1, -1);
+ imlib_filter_set_red ($filter, 0, 0, 0, 1, 1, 1);
+ imlib_filter_set_green($filter, -1, -1, 0, -1, -1, -1);
+ imlib_filter_set_green($filter, 0, 0, 0, 1, 1, 1);
+ imlib_filter_set_blue ($filter, -1, -1, 0, -1, -1, -1);
+ imlib_filter_set_blue ($filter, 0, 0, 0, 1, 1, 1);
+
+ imlib_filter_constants($filter, 0, 768, 768, 768);
+ imlib_filter_divisors ($filter, 0, 6, 6, 6);
+
+ imlib_image_filter($im,$filter);
+
+ imlib_free_filter($filter);
+}
+
+function edge_detect($im)
+{
+ $filter=imlib_create_filter();
+
+ imlib_filter_set($filter, -1, -1, 0, -1, -1, -1);
+ imlib_filter_set($filter, -1, 0, 0, -3, -3, -3);
+ imlib_filter_set($filter, -1, 1, 0, -1, -1, -1);
+ imlib_filter_set($filter, 0, -1, 0, -3, -3, -3);
+ imlib_filter_set($filter, 0, 0, 0, 16, 16, 16);
+ imlib_filter_set($filter, 0, 1, 0, -3, -3, -3);
+ imlib_filter_set($filter, 1, -1, 0, -1, -1, -1);
+ imlib_filter_set($filter, 1, 0, 0, -3, -3, -3);
+ imlib_filter_set($filter, 1, 1, 0, -1, -1, -1);
+ imlib_filter_divisors ($filter, 0, 3, 3, 3);
+
+ imlib_image_filter($im,$filter);
+
+ imlib_free_filter($filter);
+}
+
+$im = imlib_load_image('test.jpg');
+$w=imlib_image_get_width($im);
+$h=imlib_image_get_height($im);
+$im2 = imlib_clone_image($im);
+
+edge_detect($im);
+relief($im2);
+
+imlib_blend_image_onto_image($im,$im2,0,$w/2,0,$w/2,$h,$w/2,0,$w/2,$h,0,1,0);
+
+Header('Content-type: image/jpeg');
+
+imlib_dump_image($im);
+imlib_free_image($im);
+imlib_free_image($im2);
+
+?>
diff --git a/examples/pstext.php b/examples/pstext.php
new file mode 100644
index 0000000..93c9153
--- /dev/null
+++ b/examples/pstext.php
@@ -0,0 +1,10 @@
+<?php
+
+$fnt = imlib_psloadfont("ariam___.pfb");
+$im = imlib_create_image(300,50);
+imlib_image_fill_rectangle($im,0,0,300,50,0,150,150,255);
+imlib_pstext($im,'Text String...',$fnt,30,5,20,255,255,0,255,100,100,-5,16);
+header('Content-type: image/png');
+imlib_dump_image($im);
+
+?> \ No newline at end of file
diff --git a/examples/scale.php b/examples/scale.php
new file mode 100644
index 0000000..33be4c9
--- /dev/null
+++ b/examples/scale.php
@@ -0,0 +1,30 @@
+<?php
+
+if (!isset($file) || $file == 'none')
+{
+ ?>
+ <form method="post" action="<?= $PHP_SELF ?>" enctype="multipart/form-data">
+ Filename<br><input type="file" name="file"><br>
+ <input type="submit" name="Scale">
+ </form>
+ <?php
+}
+else
+{
+ $src = imlib_load_image($file);
+ $width = imlib_image_get_width($src);
+ $height = imlib_image_get_height($src);
+ $ratio = $height / $width;
+ $dst = imlib_create_cropped_scaled_image($src, 0,0, $width,$height,
+ 200, 200 * $ratio);
+
+ // Alternatively, you could simply say
+ //$dst = imlib_create_scaled_image($src, 200, '');
+
+ Header('Content-type: image/' . imlib_image_format($src));
+ imlib_dump_image($dst);
+ imlib_free_image($src);
+ imlib_free_image($dst);
+}
+
+?>
diff --git a/examples/test.jpg b/examples/test.jpg
new file mode 100644
index 0000000..bb297aa
--- /dev/null
+++ b/examples/test.jpg
Binary files differ
diff --git a/examples/text.php b/examples/text.php
new file mode 100644
index 0000000..d23def8
--- /dev/null
+++ b/examples/text.php
@@ -0,0 +1,17 @@
+<?php
+
+/*
+ * This will draw a string of text. Quite thrilling, I tell you.
+ */
+
+Header('Content-type: image/png');
+
+$fnt = imlib_load_font('./ARIAL/25');
+$im = imlib_create_image(300,50);
+imlib_text_draw($im,$fnt,5,5,'Text String in Arial.',IMLIB_TEXT_TO_RIGHT,
+ 255,255,255,255);
+imlib_dump_image($im);
+imlib_free_font($fnt);
+imlib_free_image($im);
+
+?>