Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Render Text and Shapes on Images in PHP
Sep 25, 2018 @ 12:36:25

TutsPlus.com has continued their series of posts covering the use of image manipulation functionality in PHP using the GD library. In this latest tutorial they cover drawing shapes in images and rendering fonts.

Besides using GD for manipulating regular images, we can also create our own from scratch. Different functions in the library can be used to draw basic shapes like ellipses, circles, rectangles, polygons, and simple lines. With some maths, these shapes can create nice patterns. There are also functions available to draw text on the rendered image, which opens up a lot of possibilities.

This tutorial will teach you how to draw basic shapes in PHP and how to render text using your favorite font.

The tutorial starts by explaining what functions to use to draw lines, circles, arcs, rectangles, and polygons. Example code is provided showing all of these in action together to create a basic line drawing of a house and sun. They then enhance this with changes of line thickness, color fills and the use of a "brush" created from another image to make a new house picture. The tutorial finishes with a look at how to integrate fonts into the image and insert whatever text you might want (using a true-type font).

tagged: tutorial series image manipulation part3 text shapes

Link: https://code.tutsplus.com/tutorials/rendering-text-and-basic-shapes-using-gd--cms-31767

Resize and Manipulate Images in PHP (With Examples)
Sep 14, 2018 @ 10:38:31

The NetTuts.com site has continued their series covering the use of the GD functionality in PHP to manipulate images with a new tutorial posted today. In this second part of the series they focus in on resizing and manipulating images.

In my previous tutorial, we discussed basic image manipulation using the PHP GD library. In that tutorial, I gave a brief introduction to the library and showed you how to load images from a file or create them from scratch in PHP. After that, we learned how to crop, rotate, scale and flip an image using GD. I covered the imagefilter() function to apply different filters to image resources loaded in the script. I also mentioned some useful functions in GD like imagesx() and imagesy() to get the width and height of the loaded image.

By the end of my last GD tutorial, you learned how to use the library to automate basic tasks like resizing all images in a directory or applying filters like grayscale on them before saving the final result. [...] In this tutorial, we will learn about many more useful functions in GD and how they can be used to automate more of our image manipulation tasks.

They start by looking at the imageconvolution function and the use of a "convolution matrix" and how it can be useful to blur, sharpen, emboss, or detect edges on an image. It then covers the functions used to copy images and alter the end result by changing contrast or converting to grayscale. Finally, the author shows how to use the GD functionality to dynamically add a watermark to the image and output the result to a new file.

tagged: gd graphics tutorial resize manipulate image

Link: https://code.tutsplus.com/tutorials/php-gd-image-manipulation-beyond-the-basics--cms-31766

Manipulating Images in PHP Using GD
Sep 04, 2018 @ 12:12:04

On the TutsPlus.com site they've posted a new tutorial for those needing to manipulate images in their PHP applications. In this new tutorial they walk you through the basics of using the GD image processing functionality that's included in every PHP release.

The internet would be pretty dull without images. However, maintaining and manipulating hundreds or thousands of images for your web site can be a headache. As your site design changes, you might need to modify all your images—for example, you might need to convert all your images to grayscale or resize them to 50% of their original size. You might also want to compress or crop different images. Doing this manually is time-consuming and error-prone, but with a little programming knowledge it can be automated.

In this tutorial, you will learn about the GD (Graphic Draw) library in PHP. You'll see how this library can be used to manipulate images by resizing, cropping, rotating or filtering them.

The post starts with a bit of background on GD and how to set it up on Windows versus Unix-based environments. They then get into some of the functionality that comes with GD including:

  • getting data about the image
  • flipping and rotating
  • applying filters (ex: brightness, contrast)

The post also includes two "real world" examples of GD in use: resizing an entire directory of images and applying grayscale/contrast filters to images.

tagged: manipulating image gd tutorial introduction

Link: https://code.tutsplus.com/tutorials/manipulating-images-in-php-using-gd--cms-31701

SitePoint PHP Blog:
Improving Performance Perception: On-Demand Image Resizing
Jul 03, 2018 @ 12:08:20

The SitePoint PHP blog has continued their series covering the creation of an online image gallery application. The series has included several tutorials covering performance and optimization improvements. In this latest article they continue that trend focusing on optimizing the resizing of the images.

We’ve been building a sample application — a multi-image gallery blog — for performance benchmarking and optimizations. At this point, our application serves the same image regardless of the resolution and screen size it’s being served in. In this image resizing tutorial, we’ll modify it to serve a resized version depending on display size.

They start by listing out the requirements for the improvement: make all images responsive and the addition of the code to generate the resized image. Next it discusses the state of responsive images on the web and shows the first additions to the templates for the "srcset" value. They create some helper methods in Twig to get the image URL and "srcset" value. Next up, the tutorial helps you install the league/glide package and use it to create a script to manually "serve" the resized image information back to the user.

tagged: performance image resize tutorial series ondemand

Link: https://www.sitepoint.com/improving-performance-perception-on-demand-image-resizing/

SitePoint PHP Blog:
Building an Image Gallery Blog with Symfony Flex (Parts 1 & 2)
Jun 21, 2018 @ 11:48:56

On the SitePoint PHP blog they've kicked off a series by Zoran Antolovic walking through the creation of a blog application using the latest from the Symfony project - Symfony Flex.

Our journey towards a stable, robust, high-performance web app will start with the simple but functional application — the so-called minimum viable product (MVP). We’ll populate the database with random content, do some benchmarks and improve performance incrementally. Every article in this series will be a checkpoint on our journey!

This article will cover the basics of setting up the project and organizing files for our Symfony Flex project. I’ll also show you some tips, tricks and helper scripts I’m using for speeding up the development.

So far they've posted the first two articles of the series:

  • Part one explaining some of the basics of Flex and getting the application set up (including some sample fixture data)
  • Part two showing how to populate the application with more realistic data, run some basic performance tests and create a first unit test

There's much more to come in the series including the creation of file (image) upload handling, user registration and login and the creation of image galleries from uploads.

tagged: image gallery blog tutorial symfonyflex symfony flex part1 part2

Link: https://www.sitepoint.com/building-image-gallery-blog-symfony-flex-setup/

Sameer Borate:
Unpacking binary data in PHP
Apr 04, 2018 @ 09:19:40

Sameer Borate has a new post to his Code Deisel blog showing how to unpack binary data in PHP making use of the pack and unpack functions.

Working with binary files in PHP is rarely a requirement. However when needed the PHP ‘pack’ and ‘unpack’ functions can help you tremendously. To set the stage we will start with a programming problem, this will keep the discussion anchored to a relevant context. The problem is this : We want to write a function that takes a image file as an argument and tells us whether the file is a GIF image; irrelevant with whatever the extension the file may have. We are not to use any GD library functions.

He starts by briefly covering the "metadata" that binary files contain in their headers about the type of file and, more specifically, what the content for a GIF looks like. He follows this with an example of using unpack to provide a readable version of the file's binary content. He then uses this in an is_gif function to read the contents of a file, check the header format and ensure the version is either GIF87a or GIF89a. He also includes the code for another method to get attributes about the file like height, width and the aspect ratio. He ends the post with more details on the contents of the header and what each character means.

tagged: binary data unpack pack tutorial gif image

Link: https://www.codediesel.com/php/unpacking-binary-data/

Laravel News:
Uploading Avatar Images with Spatie’s Media Library
Mar 26, 2018 @ 10:48:05

On the Laravel News site, there's a new tutorial posted showing how you can use the Spatie Media Library package to help with the file uploads in your Laravel-based application to upload avatars for your users.

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](https://github.com/spatie/laravel-medialibrary) package.

The remainder of the tutorial then breaks the implementation down into three steps:

  • Change the User Registration Form (to include the "avatar" field)
  • Upload and Store with the Media Library (installing the relation and changing the models)
  • Show an Avatar Thumbnail in the Top Navigation (using the package to resize the image)

Each step in the process includes the code or commands required to complete it. There are also several screenshots to help ensure you have the right information stored in your database.

tagged: tutorial upload avatar image spatie medialibrary package

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

Symfony Finland:
PHP-PM 1.0 launches with Docker images and Symfony 3+ support
Jan 09, 2018 @ 09:37:01

As is mentioned in this post on the Symfony Finland site, the PHP-PM project has hit their first stable release, v1.0, that includes some nice tools as well.

Running an application server written in PHP has been feasible for some years. One of the robus mature options for this has been PHP-PM, a process manager. Now the project has reached a major milestone with the release of 1.0.

The PHP-PM team released the first stable release on 8th of January 2018. It builds on the work done for some years and it builds on ReactPHP. ReactPHP is a low-level library for event-driven programming in PHP.

PHP-PM allows creating long running PHP processes that serve applications directly instead of relying an embedded PHP (like with Apache's mod_php) or a web server with PHP process manager (as with Nginx and PHP-FPM).

Updates for this release include the addition of bridges for static handling, PSR-7 integration and version bumps for Symfony components used in the system. You can check out the full list of changes in the release notes if you want to see more. The post also links to other articles with more reading and tutorials covering PHP-PM and how to put it to use (including Docker integration and basic benchmarks).

tagged: phppm process manager stable version release docker image symfony update project

Link: https://symfony.fi/entry/php-pm-1-0-launches-with-official-docker-images

Deferring Tasks in Laravel Using Queues
Dec 18, 2017 @ 12:55:39

The TutsPlus.com site has a new tutorial posted for the Laravel users showing how to defer tasks to queues using functionality already included in the framework.

In this article, we're going to explore the Queue API in the Laravel web framework. It allows you to defer resource-intensive tasks during script execution to enhance the overall end user experience. After introducing the basic terminology, I'll demonstrate it by implementing a real-world example.

The article starts by talking about some of the advantages of using queues to help with reducing page load times and improving the overall performance/quality of your site's user experience. It then starts in on the Laravel-specific pieces of the queuing puzzle including the queue drivers, connection types and the queues themselves. Next they move on to the code, showing how to create a simple first job that will manipulate the images a user uploads. The post includes the code to create the "jobs" table, build the "Images" model and the "ProcessImageThumbnails" job that will build the smaller thumbnail images from larger ones. Finally they create the controller and views for the upload handling, show how to delegate it to the job for the image processing and run the queue processor do to the actual work.

tagged: laravel tutorial task queue delegate image processing thumbnail

Link: https://code.tutsplus.com/tutorials/deferring-tasks-in-laravel-using-queues--cms-29957

Stefan Koopmanschap:
Customizing Sculpin: Highlight image and Facebook
Jul 28, 2017 @ 11:14:15

Stefan Koopmanschap has a new post to his site showing the Sculpin users out there how to customize the system for a highlight image and Facebook integration.

Over the past months I've been slowly customizing my Sculpin installation for this blog to fit my own liking a bit more. I've added a bit more styling including a beautiful background image and a transparent white background for the content column. Today I wanted to add a bit more. Two things specifically: I wanted to control a bit more about how my blogposts are displayed when they are shared on Facebook [and] I wanted to have an optional image at the top of blogposts to make them look a bit better.

It turns out this was actually quite easy, so here's a short description of what I did to make it work.

He splits the article into these two parts, showing how to add in custom markup and add custom frontmatter to modify the Facebook posts. He then shows how to add a block to the main templates for the highlight image and a small section to credit the photo back to the original.

tagged: sculpin facebook integration highlight image tutorial meta template credit

Link: https://leftontheweb.com/blog/2017/07/28/Customizing-Sculpin-highlight-image-and-facebook/