Skip to content

Commit d2176fc

Browse files
committed
Library life begin
1 parent 902a02a commit d2176fc

20 files changed

+1995
-1
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea/
2+
composer.phar
3+
vendor/
4+
example/resized/

README.md

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
1-
# image-resize
1+
ImageResize
2+
===========
3+
24
Image resizing library
5+
6+
Examples
7+
--------
8+
9+
```php
10+
use Alexantr\ImageResize\Image;
11+
12+
$src = Image::init('uploads/pic.jpg')->crop(200, 200);
13+
$src = Image::init('uploads/pic.jpg')->silhouette()->quality(95)->fit(200, 200);
14+
$src = Image::init('uploads/pic.jpg')->fitWidth(200);
15+
$src = Image::init('uploads/pic.jpg')->fitHeight(200);
16+
$src = Image::init('uploads/pic.jpg')->bgColor('6af')->place(200, 200);
17+
```
18+
For PHP >= 5.4:
19+
20+
```php
21+
$src = (new Image('uploads/pic.jpg'))->crop(200, 200);
22+
```
23+
24+
Creator example
25+
---------------
26+
27+
.htacces file:
28+
29+
```
30+
RewriteEngine On
31+
RewriteCond %{REQUEST_FILENAME} !-f
32+
RewriteCond %{REQUEST_FILENAME} !-d
33+
RewriteRule ^resized/(.*)$ image.php?path=$1 [L]
34+
```
35+
36+
image.php file:
37+
38+
```php
39+
<?php
40+
require '../vendor/autoload.php';
41+
42+
$webroot = __DIR__;
43+
$path = isset($_GET['path']) ? $_GET['path'] : '';
44+
45+
Alexantr\ImageResize\Creator::create($webroot, $path);
46+
```

composer.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "alexantr/image-resize",
3+
"type": "library",
4+
"description": "Image resizing library",
5+
"keywords": ["image", "gd", "thumbnail"],
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Alex Yashkin",
10+
"email": "[email protected]",
11+
"homepage": "http://yashkin.by/"
12+
}
13+
],
14+
"require": {
15+
"php": ">=5.3.3",
16+
"ext-fileinfo": "*"
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"Alexantr\\ImageResize\\": "src"
21+
}
22+
},
23+
"extra": {
24+
"branch-alias": {
25+
"dev-master": "1.0-dev"
26+
}
27+
}
28+
}

composer.lock

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/.htaccess

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<IfModule mod_rewrite.c>
2+
RewriteEngine On
3+
RewriteCond %{REQUEST_FILENAME} !-f
4+
RewriteCond %{REQUEST_FILENAME} !-d
5+
RewriteRule ^resized/(.*)$ image.php?path=$1 [L]
6+
</IfModule>

example/image.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
require '../vendor/autoload.php';
4+
5+
$webroot = __DIR__;
6+
$path = isset($_GET['path']) ? $_GET['path'] : '';
7+
8+
Alexantr\ImageResize\Creator::create($webroot, $path);

example/index.php

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
require '../vendor/autoload.php';
3+
4+
use Alexantr\ImageResize\Image;
5+
6+
// base examples
7+
8+
$src = Image::init('uploads/folder/antelope_canyon.jpg')->crop(150, 150);
9+
test_image($src);
10+
11+
$src = Image::init('uploads/folder/floating_leaves.jpg')->fitHeight(150);
12+
test_image($src);
13+
14+
$src = Image::init('uploads/Cat.jpeg')->crop(150, 150);
15+
test_image($src);
16+
17+
$src = Image::init('uploads/Cat.jpeg')->noTopOffset()->crop(150, 150);
18+
test_image($src);
19+
20+
$src = Image::init('uploads/cat.gif')->fitWidth(150);
21+
test_image($src);
22+
23+
$src = Image::init('uploads/Apple.png')->place(120, 150);
24+
test_image($src);
25+
26+
// wrong url
27+
$src = Image::init('folder/foo.bar')->crop(150, 150);
28+
test_image($src);
29+
30+
echo "<br>\n";
31+
32+
// quality examples
33+
34+
$src = Image::init('uploads/folder/antelope_canyon.jpg')->quality(100)->crop(250, 200);
35+
test_image($src);
36+
37+
$src = Image::init('uploads/folder/antelope_canyon.jpg')->quality(50)->crop(250, 200);
38+
test_image($src);
39+
40+
$src = Image::init('uploads/folder/antelope_canyon.jpg')->quality(10)->crop(250, 200);
41+
test_image($src);
42+
43+
$src = Image::init('uploads/folder/floating_leaves.jpg')->quality(60)->fitHeight(200);
44+
test_image($src);
45+
46+
echo "<br>\n";
47+
48+
// placeholder examples
49+
50+
$src = Image::init('uploads/not-found.jpeg')->crop(170, 150);
51+
test_image($src);
52+
53+
$src = Image::init('uploads/not-found.gif')->silhouette()->noTopOffset()->crop(170, 150);
54+
test_image($src);
55+
56+
$src = Image::init('uploads/not-found.png')->silhouette()->crop(110, 150);
57+
test_image($src);
58+
59+
$src = Image::init('uploads/not-found.png')->disableAlpha()->bgColor('36c')->place(200, 150);
60+
test_image($src);
61+
62+
echo "<br>\n";
63+
64+
// background examples
65+
66+
$src = Image::init('uploads/Apple.png')->fit(180, 150);
67+
test_image($src);
68+
69+
$src = Image::init('uploads/Apple.png')->disableAlpha()->bgColor('3366cc')->place(150, 150);
70+
test_image($src);
71+
72+
$src = Image::init('uploads/Apple.png')->disableAlpha()->bgColor('c36')->place(180, 150);
73+
test_image($src);
74+
75+
echo "<br>\n";
76+
77+
// original size. copy?
78+
79+
$src = Image::init('uploads/cat.gif')->crop(100, 100);
80+
test_image($src);
81+
82+
/**
83+
* img tag helper
84+
* @param $src
85+
*/
86+
function test_image($src)
87+
{
88+
echo '<img src="' . $src . '" alt="" style="border: 1px solid #000;">' . "\n";
89+
}

example/uploads/Apple.png

228 KB
Loading

example/uploads/Cat.jpeg

42.4 KB
Loading

example/uploads/cat.gif

10.7 KB
Loading
80.8 KB
Loading
71.5 KB
Loading

0 commit comments

Comments
 (0)