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

SitePoint PHP Blog:
How to Build a NASA Photo Gallery with Zend Expressive
Nov 03, 2015 @ 09:52:06

The SitePoint PHP blog has a new tutorial from author Andrew Carter showing you how to create a NASA photo gallery application with the latest framework offering from Zend, Zend Expressive.

In this article, we are going to use Zend Expressive to build a photo gallery using the NASA Astronomy Picture of the Day API. The end result will be the AstroSplash website which was created for the purpose of this article. [...] Zend Expressive is an exciting new micro-framework for building PSR-7 middleware applications. [...] Middleware is a term that will be used a lot in this article. A good definition of middleware is given by the Zend Expressive documentation.

They walk you through the basics of the application and how to set up an account and application over on the NASA API. They help you create the initial project, what the output should look like and commands to remove some extra code. They include the configuration of the container, set up the route middleware, work with the templating for the app and connecting it with Doctrine for database storage. Finally they integrate the NASA API using this library and pull down the latest images from the service.

tagged: zendexpressive tutorial nasa image application api framework middleware

Link: http://www.sitepoint.com/build-nasa-photo-gallery-zend-expressive/

SitePoint PHP Blog:
Docker and Dockerfiles Made Easy!
Oct 16, 2015 @ 15:56:58

The SitePoint PHP blog has a post that aims to help you with Docker and introduces some of the basic concepts and steps to understand the Dockerfile configuration.

It’s become second nature for developers to use Virtual Machines to configure and manage their working environments. Most professionals who use VMs use Vagrant for dealing with their development environments. In this article, we’ll be moving from Vagrant to Docker, and use a small Laravel application to test that everything is working as expected.

They walk you through the installation of necessary tools, creation of a simple Docker machine and the concepts behind images and containers. They show you how to create a simple Ubuntu-based machine and configuring it to serve up the default Ubuntu+Apache page. They also cover container volumes, a method for keeping a local folder in sync with one in your instance. They help you set this up with a Laravel installation. Next up they help you configure the database container running MySQL and connect it to the Laravel instance. The tutorial also shows how to set up links between the containers, gets into some of the details of the Dockerfile structure and using "docker compose" to easily create environments based off a YAML configuration.

tagged: docker dockerfiles tutorial environment container image laravel

Link: http://www.sitepoint.com/docker-and-dockerfiles-made-easy/

Programming With Yii2: Rich Text Input With Redactor
Jun 19, 2015 @ 10:38:55

NetTuts.com continues their series about programming with the Yii2 framework in this new article moving on to the use of the Redactor rich text editor that comes bundled with the framework.

In this Programming With Yii2 series, I'm guiding readers in use of the newly upgraded Yii2 Framework for PHP. In this tutorial, I'm going to introduce you to using the rich text editor Redactor within the Yii Framework. For these examples, we'll continue to imagine we're building a framework for posting simple status updates, e.g. our own mini-Twitter.

Thanks to the Yii community purchasing an unlimited license for the Redactor rich text editor, it's easy to install and use via the "yii2-redactor" extension. They help you get it installed and update a sample form to use it instead of the normal basic HTML textarea for content input. They also show you how to add image support and what it looks like both inline in the editor and the resulting HTML output.

tagged: yii2 series tutorial programming redactor richtext editor image

Link: http://code.tutsplus.com/tutorials/programming-with-yii2-rich-text-input-with-redactor--cms-23174

New Media Campaigns:
Docker for PHP Developers
Jun 02, 2015 @ 10:29:38

The New Media Campaigns site has posted a new tutorial today introducing PHP developers to Docker, the handy tool to create containers for your applications a bit simpler and more efficient than just something like Vagrant.

I've used Vagrant to manage local development servers for several years. Vagrant is, according to its official website, a tool to "create and configure light-weight, reproducible, and portable development environments." [...] However, Vagrant has one large downside—it implies hardware virtualization. This means each project runs atop a full virtual machine, and each virtual machine has a complete operating system that demands a large overhead in system resources.

[...] There is another solution, though. Have you heard of Docker? I first heard this word a year ago. It's all about containers, I was told. Awesome. What are containers?, I thought. I dug deeper, and I read all about containerization, process isolation, and union filesystems.

He starts with a brief introduction to what Docker is and two of the key concepts: containers and images. He then talks about how Docker is different from Vagrant, including the extensibility and lighter resource demands. Following all this he starts in on building an actual application in a container. He walks you through each step, including commands, to build the container and image that will result in the final instance running Ubuntu, MySQL, Nginx and PHP-FPM. He sets up a simple "Hello World" page and shows how to configure the Nginx server to serve it up as well as the MySQL server to cooperate with PHP and run locally.

tagged: docker introduction container image configure server setup tutorial

Link: http://www.newmediacampaigns.com/blog/docker-for-php-developers

SitePoint PHP Blog:
Creating Custom Field Formatters in Drupal 8
Mar 12, 2015 @ 12:29:01

The SitePoint PHP blog has a new tutorial posted today showing how to create custom field formatters in a Drupal 8 application. Custom formatters allow you to enhance the current functionality of objects in the application and extend them with additional functionality.

With the introduction of annotated plugins, a lot has changed in Drupal 8. We have a more streamlined approach to describing and discovering pieces of functionality that extend the core. Along with many other components, the former Field API (part of the larger and consolidated Entity API) is now based on plugins. In this tutorial we will go through defining a custom field formatter for an existing field (image). What we want to achieve is to make it possible to display an image with a small caption below it. This caption will be the title value assigned to the image if one exists.

They start with a new custom module, starting with just the YAML configuration. Then they help you create the field formatter as a plugin in the "Plugin/Field/FieldFormatter" namespace (code included). They explain how this code works and show how to add it as a hook to make it available to the template layer. Finally they show it in use and how it places the title value into the image caption in the result.

tagged: drupal8 custom field formatter tutorial plugin image title

Link: Creating Custom Field Formatters in Drupal 8

Laravel News:
Easy Image Processing in Laravel with Glide
Jan 30, 2015 @ 10:06:41

On the Laravel News site there's a new post sharing a video tutorial of how to use the Glide image handling library with your Laravel-based application.

Glide is a new package by Jonathan Reinink which is an on-demand image manipulation library. In this video he shows you how to set it up and the basic usage in Laravel 5.

In the tutorial Jonathan walks you through an introduction to the library and how it wraps around the Intervention image handling. He creates a basic application that, when an image endpoint is called, output the image with any given configuration options (like height and width). Glide is one of many packages making up The PHP League.

tagged: laravel image processing glide library thephpleague screencast video

Link: https://laravel-news.com/2015/01/using-glide-laravel/

SitePoint PHP Blog:
Image Scraping with Symfony's DomCrawler
Mar 31, 2014 @ 09:06:43

On the SitePoint PHP blog today there's a new post showing you how to use the Symfony DomCrawler component to scrape content, images mostly, from a remote website. The DomCrawler is one component of the Symfony framework.

A photographer friend of mine implored me to find and download images of picture frames from the internet. I eventually landed on a web page that had a number of them available for free but there was a problem: a link to download all the images together wasn't present. I didn't want to go through the stress of downloading the images individually, so I wrote this PHP class to find, download and zip all images found on the website.

He talks briefly about how the class works and then gets into the contents of the class. He walks through all the code and explains in chunks what each part does in the lifecycle of the request. The end result is a Zip archive file of all images from the remote website, packaged up for easy transport.

tagged: domcrawler symfony framework component tutorial image scrape

Link: http://www.sitepoint.com/image-scraping-symfonys-domcrawler/

Cropping Images in PHP Based on their Entropy
Feb 03, 2014 @ 11:25:42

On the CodeGeekz site there's a new post showing you how to use the Imagick extension and a custom library to crop images based on their entropy (keeping the "busiest" part of the image).

The need to resize and crop images in order to create thumbs, is a very common scenario for most websites. For example a blog like this one uses images in the content of the posts, images which at some point are used to create a thumb for the homepage. In most cases, the thumb’s dimensions are not dynamic but are static throughout the website in order to better fit the template. This however creates a major problem when we try to automatically resize and crop our images in the desired dimensions.

He starts with an example of the normal kind of cropping based on a given height and width. He points out an issue with "smart cropping" and resizing the image with the cropping is done. Instead, he's made use of Imagick in his library to produce a better cropped image based on the parts of the image with the most entropy.

tagged: crop image entropy busy resize smart tutorial

Link: http://codegeekz.com/cropping-images-entrop/

Using Composer to Install JavaScript, CSS & Images Under the Web Document Directory
Jan 07, 2014 @ 12:36:07

On the PHPClasses.org site today there's a new post showing how to install more than just PHP packages with Composer including things like Javascript, CSS and image files.

By default Composer installs all package files under the vendor directory. If you want to install asset files in the Web document root directory, you need to resort to another solution. This Asset Manager package is a plugin that extends Composer to install any package files outside the vendor directory. Additionally, it can also read the user names and passwords from a configuration file, so you do not have to enter them every time Composer retrieves packages from repositories that may require authentication, like PHP Classes and JS Classes.

Using an asset manager plugin for Composer, he shows how to include an "extra" section into your "composer.json" for the other files. There's also an example of how to implement a custom installation action that, in this case, was used to implement the "extras" functionality. The post finishes up with a look at handling authentication in the Composer requests, using the same tool to parse a "config" section with Basic HTTP authentication information.

tagged: composer package install javascript css image assets http authentication

Link: http://www.phpclasses.org/blog/package/8429/post/1-Using-Composer-to-Install-JavaScript-CSS-and-Images-Under-the-Web-Document-Directory.html

Mikko Koppanen:
Working on images asynchronously
Dec 16, 2013 @ 10:45:35

Mikko Koppanen has a new post to his site today about working with images asynchronously - the "offline" processing of things like user uploaded images using a queuing system.

To get my quota on buzzwords for the day we are going to look at using ZeroMQ and Imagick to create a simple asynchronous image processing system. Why asynchronous? First of all, separating the image handling from a interactive PHP scripts allows us to scale the image processing separately from the web heads. [...] Secondly, separating the image processing from a web script can provide more responsive experience to the user. This doesn’t necessarily mean faster, but let’s say in a multiple image upload scenario this method allows the user to do something else on the site while we process the images in the background.

He also includes a "barebones" example of how the system would work. The first Worker script makes the connection to the queue system and sends the data off for handling. The second script does most of the actual work, pulling in the image and using Imagick to create a thumbnail image. Finally he includes an example of the use of the workers in combination to send the image data for processing.

tagged: image asynchronous processing zeromq thumbnail imagick

Link: http://valokuva.org/working-on-images-asynchronously/