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

NetTuts.com:
Resize and Manipulate Images in PHP (With Examples)
Sep 14, 2018 @ 15: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

Mark Baker:
Extending final Classes and Methods by manipulating the AST
Nov 20, 2017 @ 16:38:32

Mark Baker has an interesting post to his site where he shares a suggestion for making it easier to create unit tests for some of the more difficult parts of your unit tests. In the article he shows how to extend final classes and methods by manipulating the AST (abstract syntax tree structure) of the current code under test.

We know that we should always write unit tests for our code, and mock dependencies; but that isn’t always easy when we need to mock classes define as final, or that contain final methods. This isn’t normally a problem when we’re only working with classes within our own libraries and applications, because we control whether they are final or not, and we can type-hint these dependencies to interfaces. However, when the dependencies that we use are from external libraries, we lose that control; and it can become harder to test our own classes if we do need to mock final classes and they haven’t been built to interfaces.

He talks about how one tool, Mockery, allows some of this with its functionality but can still cause issues when mocks are passed instead of actual class instances. He then starts on a solution he has been trying to implement - a mocking library that makes use of the PHP_Parser package to make it possible to modify the structure of the code itself, not just put a wrapper (mock) around it. He includes a bit of code showing how to use that and the BetterReflection library to do some class introspection, locate files for testing and how to the tool to "de-finalize" a class (make it no longer "final").

tagged: extend class method manipulate ast testing unittest final mockery tutorial

Link: https://markbakeruk.net/2017/11/19/extending-final-classes-and-methods-by-manipulating-the-ast/

PHPClasses.org:
How to Create a PHP C Extension to Manipulate Arrays Part 2: Adding ArrayAccess and
Aug 13, 2015 @ 17:33:04

Dmitry Mamontov has posted the second part of his "How to Create a PHP C Extension to Manipulate Arrays" series on PHPClasses, building on part one and adding in the ArrayAccess and Traversable interface functionality.

In the first part of this article we learned how to create an extension for PHP written in C to create a class that works like arrays. However, to make the class objects really behave as arrays you need to implement certain interfaces in the class.

Read this article to learn how to make a PHP class defined by a C extension implement ArrayAccess and Traversable interfaces, as well understand how to solve problems that you may encounter that can make your extension slower than you expect.

He takes the class he defined in part one and walks you through the addition of the two interfaces. He shows you where they're defined in the PHP source, what the code looks like and how they integrate with the class. He also shows you how to customize the object class handlers, making it possible to use the custom class (object) as an array. Adding Traversable is easier, adding an iterator return method that allows for the data internal to the class to be iterated through.

tagged: phpclasses series part2 extension class array manipulate arrayaccess traversable

Link: http://www.phpclasses.org/blog/post/306-How-to-Create-a-PHP-C-Extension-to-Manipulate-Arrays-Part-2-Adding-ArrayAccess-and-Traversable-interfaces.html

PHPClasses.org:
How to Create a PHP C Extension to Manipulate Arrays Part 1: Basic Array Class Exten
Aug 11, 2015 @ 15:27:24

Dmitry Mamontov has posted a the first part of a series looking at manipulating arrays in the PHP source and enhancing performance for certain handing as a PHP extension.

In PHP projects, arrays are used every where because they are useful and flexible to store all sorts of data structures. However, when you need to maximize the performance the manipulation of arrays for specific purposes, you can achieve great gains if you implement a PHP extension written in the C language. Read this tutorial to learn how to build your own basic array manipulation extension in C.

He covers all the steps you'll need to get start building the extension, introduces a few key concepts and starts on the code for the extension:

  • Building PHP from the Source
  • Building a PHP Extension (overview)
  • Brief Introduction to zval and Functions
  • Defining a Class in Our Extension
  • D for Dynamic (working with dynamic array values)

The C code needed is included through out the post. The next part in the series will build on this and show how to implement interfaces like ArrayAccess and Traversable.

tagged: extension array manipulate part1 series introduction source

Link: http://www.phpclasses.org/blog/post/304-How-to-Create-a-PHP-C-Extension-to-Manipulate-Arrays--Part-1-Basic-Array-Class-Extension.html

Smashing Magazine:
Image Manipulation With jQuery and PHP GD
Apr 05, 2011 @ 17:02:30

Smashing Magazine has a new post today about using jQuery and GD to manipulate images to upload an image, crop it and save that version to the remote server.

One of the numerous advantages brought about by the explosion of jQuery and other JavaScript libraries is the ease with which you can create interactive tools for your site. When combined with server-side technologies such as PHP, this puts a serious amount of power at your finger tips. [...] Sure, there are plugins out there that you can use to do this; but this article aims to show you what’s behind the process. You can download the source files for reference.

They walk you through the little bit of setup you'll need before things will be working and then move right into the upload form and PHP handling that goes with it. The Javascript that goes with it is all home-grown (not a plugin) and cleverly uses a DIV to simulate the bounding box for the crop.

tagged: tutorial image manipulate jquery gd crop

Link:

PHPBuilder.com:
Creating and Manipulating PDFs with PHP and FPDF
Mar 11, 2011 @ 16:13:07

On PHPBuilder.com today there's a new tutorial about creating editing PDFs with the help of the FPDF library.

Because the Web has become the primary mechanism for distributing PDF documents, it's common to encounter questions on various web development forums pertinent to the dynamic creation of PDF documents using languages such as PHP. [...] Thankfully, such a demand for PDF manipulation capabilities exists within the PHP community that numerous alternative open source solutions have long been available, including notably FPDF.

They help you get the library installed and show you how to create a basic PDF with some simple text inside. They build on this and show how to add multiple text sections, images and watermarks.

tagged: manipulate pdf fpdf create tutorial

Link:

php|architect:
Image Processing with Imagine
Mar 07, 2011 @ 16:53:42

New from the php|architect blog, there's a tutorial from Mike Willbanks about using Imagine to transform images dynamically in a more object-oriented way.

Image processing in PHP is a necessary evil but is needed more often than not in just about every web application. With the various preferences in image processing libraries (think ImageMagick, GraphicsMagick and GD) it is difficult to find a library that provides a unified object oriented interface as well as implementing the general tasks in a simplistic fashion. Imagine is an open source image manipulation library built with PHP 5.3 that implements an object oriented interface to ImageMagick, GraphicsMagick and GD

Mike gives a quick sample script that uses SPL autoloading to pull in the classes as they're needed (with the "imagineLoader" method) and make a basic thumbnail from a PNG file.

tagged: imagine image process manipulate oop autoload

Link:

Padraic Brady's Blog:
Zend Framework Proposal: ZendHtmlFilter (HTML Sanitisation And Manipulation)
Sep 07, 2010 @ 15:13:17

Padraic Brady has a new post on his blog talking about a new proposal he's made for the Zend Framework about filtering and sanitizing HTML content.

For a while now, I've been keen to build a HTML Sanitisation solution for PHP. Where else would I end up putting it other than in Zend Framework? As I've explored in past articles [1] [2], HTML Sanitisation in PHP is a very inconsistent practice. [...] Isn't it possible to create a sanitiser that is both secure by default and performs well?

He talks about his Wibble tool that's become the base of his idea for a filtering feature built into the framework. It mainly uses the PHP DOM functionality and HTML Tidy for speed and parsing and was benchmarked as performing better than the HTMLPurifier tool. If you're interested, check out his proposal for its inclusion in the Zend Framework 2.0.

tagged: zendframework proposal html sanitize manipulate filter component wibble

Link:

Jeremy Cook's Blog:
Installing Imagick under Apache on Windows
Jun 08, 2010 @ 17:48:38

Jeremy Cook has put together a guide for installing Imagick on Windows so it can be used in your PHP applications..

After a few weeks of experimenting on and off I've just managed to get the Imagick extension installed under Apache on Windows (my development environment). While discovering how to make it work was not at all simple the final process of getting all the pieces to play together nicely was pretty easy. In this post I'll briefly discuss what ImageMagick and the Imagick extension for PHP are, why you might want to use them, how I got them up and running and finally a very simple piece of example code. I'm hoping this post will help people avoid the frustration and effort I went through to get them to work!

He explains what the tools (ImageMagick & Imagick) are and why it's a bit more difficult to install them on Windows than just a point and click sort of thing. He walks you through an eight-step process that will have you up and working in no time and includes a simple PHP script you can run to ensure things are working as they should.

tagged: windows imagick install tutorial image manipulate

Link:

NETTUTS.com:
CodeIgniter from Scratch: File Uploading and Image Manipulation
Feb 23, 2010 @ 14:09:17

On NETTUTS.com there's a recent tutorial - the ninth part of the "CodeIgniter from Scratch" series - posted (by Burak Guzel) for all of the users of this popular framework out there. It looks at, starting from the very beginning, how to create an upload and image manipulation script for use in the framework.

In lesson nine of our CodeIgniter series, we'll build a small image gallery that allows you to upload files, and automatically create thumbnails

He links to the previous eight parts of the series if you need to catch up as well as the source code for this installment so you can follow along with the screencast. For those more on the go, you can also download the screencast and watch it whenever.

tagged: tutorial file upload image manipulate screencast

Link:


Trending Topics: