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

TutsPlus.com:
Render Text and Shapes on Images in PHP
Sep 25, 2018 @ 17: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

Laravel News:
Twine: String Manipulation, Leveled Up
Jul 11, 2018 @ 14:19:02

On the Laravel News site there's a post spotlighting an interesting string manipulation library (Twine) and some of its basica features and use.

Twine is a stand-alone PHP 7 package by Chris Kankiewicz for string manipulation and comparison with an expressive fluid syntax.

They provide several code examples showing the package in action:

  • adding padding to the left/right
  • uppercase/lowercase
  • starts with/contains/ends with
  • converting the string to a hash
  • basic string formatting

The package also makes use of a fluent interface, making it easier to stack multiple operations onto a string (like checking to see if a substring equals a value). You can find out more about the package on its GitHub repository.

tagged: string manipulation package library twine tutorial

Link: https://laravel-news.com/twine-string-manipulation-leveled-up

SitePoint PHP Blog:
Glide: Easy Dynamic on-Demand Image Resizing
Mar 03, 2016 @ 16:52:59

On the SitePoint PHP blog editor Bruno Skvorc has posted a tutorial showing you how to use Glide, an image manipulation library that's a part of the League of Extraordinary Packages.

Glide is an image processing library built on top of Intervention. Its purpose is to facilitate on-demand image processing. That’s a fancy way of saying it creates images as they’re requested if they don’t exist.

He gives the example of the need to manipulate the image based on the user's device - like desktop versus mobile clients. He shows how to get the library installed (via Composer) and how to configure it with cache and source directories. He then integrates the library into a "no framework"-based application, passing the missing image request to the "image" controller for handling. However a basic implementation like this leaves it open to exploit. He shows how to restrict the allowed sizes with an allowedWidths data set. He ends the article with a look at image saving and caching with the possibility of writing the resulting file to the local drive (caching) if re-requested later.

tagged: glide image manipulation library theleague ondemand tutorial

Link: http://www.sitepoint.com/easy-dynamic-on-demand-image-resizing-with-glide/

SitePoint PHP Blog:
Imagick vs GD
Nov 29, 2013 @ 00:16:34

In a new post to the SitePoint PHP blog Jacek Barecki has written up a comparison of two of the most widely used PHP image manipulation libraries - Imagick and GD.

If you want to create a thumbnail, apply a filter to an image or transform it in any other way, you will have to employ an image processing library in your PHP application. It means that you will probably choose GD or ImageMagick. But which one supports a wider range of image formats? Maybe one of them is slower than the other? What other criteria should be taken under consideration when choosing the right library?

He compares them on a few different aspects:

  • Availability
  • Supported file types
  • Functionality
  • Performance
  • Coding style
  • Popularity

He also provides three alternatives to using GD or Imagick, most involving outside services or software.

tagged: imagick gd image manipulation library tutorial

Link: http://www.sitepoint.com/imagick-vs-gd/

Leve.rs:
Array Manipulation in PHP, the Correct Way
Nov 08, 2013 @ 16:08:04

On the Leve.rs blog there's a recent post showing what they consider is the right way to work with arrays in PHP. It shows three things you can do to use PHP's own functionality to more correctly perform some common array operations.

More often than not, when PHP developers debug others’ code, the majority of each method is taken up by array manipulations. Spending this much time on array manipulations is a huge hassle when trying to understand any given method. In order to speed up the debugging process, it’s important to start writing array manipulations the correct way, first. Here are a few examples of code I have either written myself or had to fix in the past. It is time every PHP developer knows how to manipulate arrays properly!

Their three tips relate to:

  • Merging Arrays
  • Array Value Manipulation (with array_walk)
  • Array Value Manipulation (append with the plus sign, "+")
tagged: array manipulation correct merge value walk plus

Link: http://leve.rs/blog/correct-array-manipulation-in-php/

Mikko Koppanen:
Imagick Refresh Updates
Oct 07, 2013 @ 14:21:50

Mikko Koppanen has been posted several new items about the updates being made to the Imagick functionality in PHP (added as a PECL extension). In order o posting they are:

The Imagick extension is a more advanced image manipulation library that the built-in GD functionality. You can find out more about the functions and features it offers in its manual page.

tagged: imagick graphics manipulation update bugfix

Link: http://valokuva.org/

PHPBuilder.com:
PHP Arrays: Advanced Iteration and Manipulation
Dec 09, 2011 @ 18:50:11

In this new tutorial from PHPBuilder.com, Jason Gilmore shows you some of the more advanced things you can do with arrays in PHP (specifically in the areas of iterating through them and manipulating their contents).

Sporting more than 70 native array-related functions, PHP's array manipulation capabilities have long been one of the language's most attractive features. [...] There are however many array-related tasks which ask a bit more of the developer than merely knowing what part of the manual one needs to consult. Many such tasks require a somewhat more in-depth understanding of the native features, or are possible only when a bit of imagination is applied to the problem.

In his examples he shows how to do things like sorting a multi-dimensional array, iterating recursively (with the help of a RecursiveArrayIterator), converting an object to an array and doing "natural" sorting on an array's contents.

tagged: array manipulation advanced iteration spl recursive sort

Link:

Davey Shafik's Blog:
DateTime Timestamp Parsing
Sep 20, 2011 @ 16:24:27

In a new post to his blog Davey Shafik looks at parsing dates with DateTime, the new and improved way to handle dates in PHP (well, not so new but definitely improved).

As part of a recent project, I was tasked with taking timestamps returned by an API and displaying fuzzy dates in the final output (e.g. 3hrs ago, in 2 weeks, tomorrow). The timestamp format in question looks like: 2012-09-01T16:20:01-05:00 This format can be found in PHP as the DATE_ATOM or DateTime::ATOM constants, which contain the date() formatter string: Y-m-dTH:i:sP With this in hand, we can now easily parse the timestamp into a useful object.

Parsing the date into a DateTime object is as easy as giving it the date string and telling it how it's formatted. Then you can do all sorts of fun things. He shows how to shift the timezone by name, by time increment - simple (like "1 hour") and more complex (like "1 hour 5 minutes 3 seconds"). You can find out more about the DateTime object in the PHP manual.

tagged: datetime parsing manipulation tutorial

Link:

PHPBuilder.com:
10 PHP Tricks for Associative Array Manipulation
Dec 13, 2010 @ 17:54:34

On PHPBuilder.com there's a new tutorial with ten handy tips you can use to work with associative arrays in your PHP applications.

The associative array -- an indispensable data type used to describe a collection of unique keys and associated values -- is a mainstay of all programming languages, PHP included. [...] Such extensive support can be a bit overwhelming to developers seeking the most effective way to manipulate arrays within their applications. In this article, I'll offer 10 tips that can help you shred, slice and dice your data in countless ways.

His tips include working with the arrays by:

  • Adding Array Elements
  • Swapping Keys and Values
  • Editing Array Values
  • Randomizing Array Order
  • Searching the Array
tagged: associative array manipulation tutorial

Link:

PHPBuilder.com:
10 Easy Solutions for PHP String Manipulation
Jun 03, 2010 @ 15:04:32

If you're relatively new to the PHP language and want a few handy tips on working with strings, you should check out this list of ten things that Jason Gilmore has put together to help you with some common string manipulations.

PHP's capabilities [string manipulation] are so strong that it can sometimes be difficult to determine the best possible approach for accomplishing a particular string-related task. In this article I highlight the ideal solutions to 10 common string manipulation tasks.

Among the methods in his list of transformations, he includes:

  • Truncating Text to Produce a Summary
  • Parsing a CSV File
  • Converting URLs into Hyperlinks
  • Converting Newline Characters to Break Tags
tagged: string manipulation tutorial introductory

Link:


Trending Topics: