i.onthe.io is still operational for your use case (despite the 2017 deprecation note). If unavailable, evaluate alternatives like AWS S3, Imgix, or Cloudinary.composer require devmachine/ontheio-bundle:~1.0
app/AppKernel.php under registerBundles():
new Devmachine\Bundle\OntheioBundle\DevmachineOntheioBundle(),
new Sensio\Bundle\BuzzBundle\SensioBuzzBundle(), // Required dependency
config.yml:
devmachine_ontheio:
image:
key: "%ontheio_api_key%"
secret: "%ontheio_api_secret%"
use Devmachine\Bundle\OntheioBundle\Service\OntheioService;
$service = $this->get('devmachine_ontheio.service');
$url = 'https://example.com/image.jpg';
$response = $service->uploadUrl($url);
URL Uploads:
Use uploadUrl() to convert remote URLs to cloud-hosted assets:
$service->uploadUrl('https://example.com/photo.png', ['width' => 800]);
width, height, format, and quality.Direct File Uploads:
Stream local files via uploadFile():
$filePath = storage_path('app/image.jpg');
$service->uploadFile($filePath, ['crop' => 'fill']);
Image Processing: Chain transformations (e.g., resize + watermark):
$service->uploadUrl($url, [
'resize' => 'fit',
'width' => 600,
'watermark' => 'http://example.com/watermark.png'
]);
Service Integration:
kernel.request listeners.VichUploaderBundle for file uploads:
$form->add('image', FileType::class, [
'mapped' => false,
'constraints' => new File\FileType(['mimeTypes' => ['image/jpeg']]),
]);
class FallbackOntheioService implements OntheioServiceInterface {
public function uploadUrl($url, array $options = []) {
try {
return $this->ontheioService->uploadUrl($url, $options);
} catch (Exception $e) {
return $this->alternativeService->upload($url, $options);
}
}
}
Deprecated API:
i.onthe.io is active. Test thoroughly or replace the service URL in the bundle’s OntheioService class.# config/services.yml
devmachine_ontheio.service:
class: AppBundle\Service\MockOntheioService
SensioBuzz Dependency:
Sensio\Bundle\BuzzBundle for HTTP requests. Ensure it’s registered and configured for retries/timeouts:
sensio_framework_extra:
buzz:
client:
timeout: 30
retries: 3
Configuration Sensitivity:
config.yml. Use environment variables:
devmachine_ontheio:
image:
key: "%env(Ontheio_API_KEY)%"
secret: "%env(Ontheio_API_SECRET)%"
Error Handling:
RuntimeExceptions. Extend the service to catch specific errors (e.g., Ontheio\Exception\ApiException):
try {
$service->uploadUrl($url);
} catch (Exception $e) {
if ($e->getCode() === 403) {
// Handle forbidden access
}
}
config.yml to log API requests:
sensio_framework_extra:
buzz:
client:
plugins:
- Sensio\Bundle\FrameworkExtraBundle\Buzz\Client\LoggerPlugin
$response = $service->uploadUrl($url);
file_put_contents(storage_path('debug/ontheio_response.json'), $response->getContent());
Custom Endpoints: Override the base URL in the service:
class CustomOntheioService extends OntheioService {
protected $baseUrl = 'https://your-custom-endpoint.com';
}
New Transformations:
Extend the OntheioService to support additional parameters:
public function uploadUrl($url, array $options = []) {
$options['custom_param'] = 'value';
return parent::uploadUrl($url, $options);
}
Event Dispatching: Trigger events after uploads (e.g., for analytics):
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class EventfulOntheioService extends OntheioService {
public function __construct(EventDispatcherInterface $dispatcher) {
$this->dispatcher = $dispatcher;
}
public function uploadUrl($url, array $options = []) {
$response = parent::uploadUrl($url, $options);
$this->dispatcher->dispatch(new ImageUploadEvent($response));
return $response;
}
}
How can I help you explore Laravel packages today?