Posts tagged with image manipulation

Join thousands of developers

Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages.

No spam. Unsubscribe anytime. You can also follow me on X.

New major versions for spatie/image and Laravel Media Library have been released

by Freek Van der Herten – 11 minute read

We’ve released a new major version of spatie/image, v3. This package makes it very easy to manipulate images using PHP.

At the same time, we’ve also released a new major version of spatie/laravel-medialibrary. This is a powerhouse package that can associate all kinds of files with Eloquent models. The latest version of this package now uses spatie/image v3 under the hood for manipulating images.

In this blog post, I’ll explain why we made new major versions and how they can be used.

Read more

Uploading avatar Images with Spatie’s medialibrary

Over at Laravel News Povilas Korop wrote a nice tutorial on how to use our medialibrary (we released a new major version a couple of days ago).

By default, the Laravel registration form contains only the name, email, and password, but often it’s useful to allow the user to upload a photo or an avatar. In this tutorial we will show you an easy way to add it, using Spatie’s Media Library package.

https://laravel-news.com/uploading-avatar-images

It's a good tutorial but there's a few things not mentioned. At the end of the post you'll see this line of code:

Auth::user()->getMedia('avatars')->first()->getUrl('thumb');

That can be written a bit shorter as :

Auth::user()->getFirstMediaUrl('avatars', 'thumb');

The new v7 of the medialibrary has a new feature called "single file collections", which is just perfect for this example. Take a look at the docs: https://docs.spatie.be/laravel-medialibrary/v7/working-with-media-collections/defining-media-collections#single-file-collections

Read more

laravel-medialibrary v7 has been released ?

by Freek Van der Herten – 14 minute read

laravel-medialibrary is a powerful package that can help handle media in a Laravel application. It can organise your files across multiple filesystems, generate thumbnails, optimize images and much much more. At Spatie we use this package in nearly every project. The last few months our team has…

Read more

Laravel-medialibrary v7 preview: media collections

by Freek Van der Herten – 5 minute read

laravel-medialibrary is a package that can help handle media in a Laravel application. It can organise your files across multiple filesystems, generate thumbnails, optimize images and much much more. Like mentioned before on this blog my team and I are currently creating a new major version, v7,…

Read more

Optimize images in Laravel apps

by Freek Van der Herten – 3 minute read

A while ago we released image-optimizer. In short this package can make all kinds of images smaller by stripping out metadata and applying a little bit of compression. Read this blogpost to learn more about it. Although it's pretty easy to work with the package, we felt that we could deliver a more…

Read more

Easily optimize images using PHP (and some binaries)

by Freek Van der Herten – 7 minute read

Our recently released image-optimizer package can shave off some kilobyes of PNGs, JPGs, SVGs and GIFs by running them through a chain of various image optimization tools. In this blog post I'll tell you all about it. First, here's a quick example on how you can use it: use…

Read more

Easily convert webpages to images using PHP

by Freek Van der Herten – 4 minute read

Browsershot is a package that can easily convert any webpage into a image. Under the hood the conversion is made possible new headless options in Chrome 59. In this post I'd like to show you how you can use Browsershot v2. Here's a quick example of how it can be used:…

Read more

A package to easily manipulate images in PHP

by Freek Van der Herten – 4 minute read

Today we released a new package called image that makes manipulation images in PHP extremely easy. In this post I'd like to explain why we built it and how it can be used. Manipulating images in PHP To manipulate images in PHP there are already a lot of options. You can go hardcore and use the Gd or…

Read more

Finding differences in images with PHP

Over at Sitepoint Christoper Pitt shares some research he has done in finding differences in images using PHP.

I recently stumbled across a fascinating question: how could I tell whether an image had changed significantly? As PHP developers, the most troublesome image problem we have to deal with is how to resize an upload with an acceptable loss of quality.

In the end I discovered what many before me have – that this problem becomes relatively simple given the application of some fundamental mathematical principles. Come along with me as we learn about them…

https://www.sitepoint.com/finding-differences-in-images-with-php

Read more

Laravel medialibrary hits v4

by Freek Van der Herten – 2 minute read

Today we tagged a new major version of laravel-medialibrary. In case you're not familiar with this package here's a quick rundown of what it can do. The package can associate all sorts of files with Eloquent models. It provides a simple, fluent API to work with. Here's a quick example: $newsItem =…

Read more

Easily convert images with Glide

Glide is an easy to use image manipulation library by Jonathan Reinink. It was bumped to version 1.0.0 a few days ago. Glide can created optimized images on the fly by levering url's such as /img/users/1.jpg?w=300&h=400&fit=crop. Take a look at the example in the Glide documentation to know more.

I think Glide provides a very nice API to create image manipulations. Unfortunately it isn't very easy to use the API to generate an image using code. So I created a little package for that called laravel-glide. All new major versions of Spatie packages will require PHP 7, laravel-glide is no exception to this.

Here's an example of how to create a greyscale version image with a maximum width of 50 pixels.

GlideImage::create($pathToImage)
    ->modify(['filt'=>'greyscale', 'w'=> 50])
    ->save($pathToWhereToSaveTheManipulatedImage);

Take a look at Glide's image API to see which parameters you can pass to the modify-method.

Read more

Installing Imagick on a Forge provisioned PHP 7 server

Update added on 14th november 2017: Adding imagick on a forge provisioned server is now as simple as running sudo apt-get install php-imagick


Today I set up some PHP 7 servers on Forge. Those servers are going to be used to host some Blender based projects. Blender uses laravel-medialibrary to convert images. The package uses Imagick to do that. It turns out the Imagick PHP 7 extension isn't released yet. But there's an RC2 release candidate. Pascal Baljet provided this script to compile and install the extension.

#!/bin/bash
if [ "$EUID" -ne 0 ]
  then echo "Please run as root"
  exit
fi

apt-get install pkg-config libmagickwand-dev -y
cd /tmp
wget http://pecl.php.net/get/imagick-3.4.0RC2.tgz
tar xvzf imagick-3.4.0RC2.tgz
cd imagick-3.4.0RC2
phpize
./configure
make install
rm -rf /tmp/imagick-3.4.0RC2*
echo extension=imagick.so >> /etc/php/7.0/cli/php.ini
service php7.0-fpm restart
service nginx restart

I was a bit worried that the extension would be unstable, but all image manipulations that I need on my projects (cropping and resizing some stuff), just worked. Mandatory disclaimer: your mileage may vary.

Read more

A new version of the medialibrary package

by Freek Van der Herten – 1 minute read

When starting out with Laravel I made a medialibrary to associate uploaded files with models. In our custom made cms we use the medialibrary to for example associate articles with images. In short the medialibrary could: associate files with models generate thumbnails and other derived images from…

Read more