Skip to content

Commit

Permalink
Added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sprain committed Aug 14, 2012
1 parent 6debdc6 commit 6628507
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/example1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
include('../class.Images.php');

//Create a new object, send relative or absolut path to your image
$image = new Image('../test/image1.png');

//We can rotate the image
$image->rotate(90);

//and we can resize and crop it to have a nice thumbnail
$image->resize(150,150,'crop');

//lets see what we have!
$image->display();
18 changes: 18 additions & 0 deletions examples/example2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

//first same stuff as in example1.php
include('../class.Images.php');
$image = new Image('../test/image1.png');
$image->rotate(90);
$image->resize(150,150,'crop');

/*
Now save the file. First give a filename (without file extension, the class will figure it out!)
Then, optionally, give path to the folder where you want the image to be saved.
Of course, this directory will have to be writable! */
$image->save("newFilename", "../test");

/*
and... oh pretty wow! If the path of the image is accessible to the browser
you can now even display the whole HTML code of the <img>-Tag */
$image->displayHTML();
38 changes: 38 additions & 0 deletions examples/example3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
include('../class.Images.php');

$mainImage = '../test/image2.jpg';
$pathToSaveFiles = '../test'; //must be writable

/*
If you resize an image, the standard value is 'fit'. This means, your image
will be resized so it fits within the provided width and height without
losing its aspect ratio. So what you deliver is basically the maximum
width and height of the new image, but very likely one side of the
image will turn out smaller. */

$image = new Image($mainImage);
$image->resize(300,100);
$image->save('fit', $pathToSaveFiles);
$image->displayHTML();


/*
If you set the option 'fill' the image will fill the whole width and
height you provided. But it will loose it aspect ratio. So be ready
to see your image deformed.*/

$image = new Image($mainImage);
$image->resize(300,100, 'fill');
$image->save('fill', $pathToSaveFiles);
$image->displayHTML();


/*
If you choose to 'crop' the image, it won't lose its aspect ratio but
parts of the image will be cut off. */

$image = new Image($mainImage);
$image->resize(300, 100, 'crop');
$image->save('crop', $pathToSaveFiles);
$image->displayHTML();
30 changes: 30 additions & 0 deletions examples/example4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
include('../class.Images.php');

$mainImage = '../test/image3.jpg';
$pathToSaveFiles = '../test'; //must be writable

/*
Now, there’s more to cropping! You can choose
which part of the original image you want to see on
the cropped image.
Simply set l, r, or c for left, right or center
and b, t or c for bottom, top or center.
Go play around, not all combinations make sense
for every image. It depends whether the
image’s format is landscape or portrait. */

$image = new Image($mainImage);
$image->resize(400, 400, 'crop', 'l', 'b');
$image->save('left-bottom', $pathToSaveFiles);
$image->displayHTML();

$image = new Image($mainImage);
$image->resize(400, 400, 'crop', 'r', 't');
$image->save('right-top', $pathToSaveFiles);
$image->displayHTML();

$image = new Image($mainImage);
$image->resize(400, 400, 'crop', 'c', 'c');
$image->save('center-center', $pathToSaveFiles);
$image->displayHTML();
13 changes: 13 additions & 0 deletions examples/example5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
include('../class.Images.php');

/*
Let’s say you want your user to upload an image which has an exact aspect ratio of 1:2.
How do you check that? Nothing easier than that! */

$image = new Image('../test/image3.jpg');
if($image->checkRatio(1,2)){
print 'Yes, you made it!';
}else{
print 'Sorry dude, the actual ratio is 1:' . round($image->getRatioWidthToHeight(), 2);
}
18 changes: 18 additions & 0 deletions examples/example6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
include('../class.Images.php');

//There’s so much to know about an image. Go get some information!

$image = new Image('../test/image3.jpg');

print 'Width: '.$image->getWidth().'<br />';
print 'Height: '.$image->getHeight().'<br />';
print 'Extension: '.$image->getExtension().'<br />';
print 'Mime: '.$image->getMimeType().'<br />';
print 'Type: '.$image->getType().'<br />';
print 'Filesize in Bytes: '.$image->getFileSizeInBytes().'<br />';
print 'Filesize in kBytes: '.$image->getFileSizeInKiloBytes().'<br />';
print 'Filesize readable: '.$image->getFileSize().'<br />';
print 'Ratio Width:Height: '.$image->getRatioWidthToHeight().'<br />';
print 'Ratio Height:Width: '.$image->getRatioHeightToWidth().'<br />';
print 'Is it RGB?: '.$image->isRGB();
12 changes: 12 additions & 0 deletions examples/index.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h1>Some examples for class.Images.php</h1>

<p>Here are some examples of what you can do with this class. Make sure to check the source code of those files as well as of the class itself as well as there are plenty of more parameters and options.</p>

<ul>
<li><a href="example1.php">#1: Basic example: Image rotation and cropping</a></li>
<li><a href="example2.php">#2: Save files and display html</a></li>
<li><a href="example3.php">#3: Cropping options: fill, fit and crop</a></li>
<li><a href="example4.php">#4: Crop it like it's hot! More cropping options.</a></li>
<li><a href="example5.php">#5: Check image ratio.</a></li>
<li><a href="example6.php">#6: Get all the information about your image.</a></li>
</ul>

0 comments on commit 6628507

Please sign in to comment.