You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's a longer example at the end of the readme.
36
+
35
37
### Methods
36
38
37
39
#### `API($username)` constructor
@@ -97,6 +99,55 @@ All methods throw on error. You can expect the following exception subclasses:
97
99
*`ImageOptim\NotFoundException` is thrown when URL given to `imageFromURL()` returned 404. Make sure paths and urlencoding are correct. [More](https://im2.io/api/post#response).
98
100
*`ImageOptim\OriginServerException` is thrown when URL given to `imageFromURL()` returned 4xx or 5xx error. Make sure your server allows access to the file.
99
101
102
+
If you're writing a script that processes a large number of images in one go, don't launch it from a web browser, as it will likely time out. It's best to launch such scripts via CLI (e.g. via SSH).
103
+
100
104
### Help and info
101
105
102
106
See [imageoptim.com/api](https://imageoptim.com/api) for documentation and contact info. I'm happy to help!
107
+
108
+
### Example
109
+
110
+
This is a script that optimizes an image. Such script usually would be ran when a new image is uploaded to the server. You don't need to run any PHP code to *serve* optimized images.
111
+
112
+
The API operates on a single image at a time. When you want to generate multiple image sizes/thumbnails, repeat the whole procedure for each image at each size.
113
+
114
+
```php
115
+
<?php
116
+
117
+
// This line is required once to set up Composer
118
+
// If this file can't be found, try changing the path
119
+
// and or run `composer update` in your project's directory
120
+
require "vendor/autoload.php";
121
+
122
+
$api = new ImageOptim\API("🔶your api username goes here🔶");
123
+
124
+
// imageFromURL/imageFromPath creates a temporary object used to store
0 commit comments