educational

Image Manipulation Using PHP

I bet that many of you who develop websites have had this problem at least one time: how to resize, rotate and manipulate pics using PHP. I myself had this problem some time ago, and so I searched for the best solution. Among the options I found was a tool called ImageMagick.

ImageMagick is a standalone, command-line program that can be called with parameters to perform a requested change to either a single image, or to a set of images. ImageMagick is by far more complex than any other image processing tool I found, and although there may be other tools, I can recommend this one.

Since all of your image processing can be easily done by this tool, all you have to do is to install it on your Web server and then call it with the proper parameters. If you are using a Linux Web server, there are some configuration issues that you have to take care of, such as specifying full paths (paths from the root folder, not relative paths), and setting ‘umask’ to "0" in order to prevent changing file permissions in a way that will cause you problems in the future.

Here are some examples of how you can use ImageMagick:

• To Make Thumbnails:

<?
// Set the path to where the ImageMagick program is on your server
$path_imagemagick="/usr/X11R6/bin/";

// Set the path and filename to the picture
$path_picture="/www/sitename/pictures/picture1.jpg";

// Set the path and filename to where the thumb will be created
$path_thumb="/www/sitename/thumbs/thumb1.jpg";

// Set the largest dimension of the thumbnail (width for landscape and height for portraits)
$thumbnail_size=120;

// Set umask to 0 in order not to affect the file permissions during the next operation
umask(000);

// Execute the shell command that calls Image Magick with the proper parameters (as set above)
$ok=shell_exec($path_imagemagick."convert -size $thumbnail_size $path_picture -geometry $thumbnail_size $path_thumb");

// If shell_exec above returns 1 this mean that the operation was sucessful.
if ($ok)
{
echo "Thumbnail Created OK";
}

?>

• To Resize Images:
This is done the same way as above, except that the $path_thumb (which is the destination file) will have the same value as $path_picture – and this way the script will resize the original image, rather than create a new image.

• To Rotate Images:
To rotate an image, you must decide how much to rotate it (the number of degrees), and in which direction. Actually, all you have to know is the number of degrees you wish to rotate, since the direction is indicated by the plus and minus sign. So, +90 degrees means to rotate the pic counter clockwise for a quarter of circle (full circle is 360 degrees); -90 meens to rotate it clockwise for a quarter of circle:

<?
// Set the path to where the ImageMagick program is on your server
$path_imagemagick="/usr/X11R6/bin/";

// Set the path and filename to the picture
$path_picture="/www/sitename/pictures/picture1.jpg";

// Set the degrees with whom the picture will be rotated. Positive means counter clockwise and negative clockwise.
$degrees=-90;

// Set umask to 0 in order not to affect the file permissions with the next operation
umask(000);
$ok=shell_exec ($path_imagemagick."convert -rotate $degrees $path_picture $path_picture");

// If shell_exec above returns 1 this mean that the operation was sucessful.
if ($ok)
{
echo "Picture Rotated OK";
}

?>

• Apply A Watermark:

To do this, you will need to have an aditional image that will be used for the watermark.

<?
// Set the path to where the ImageMagick program is on your server
$path_imagemagick="/usr/X11R6/bin/";

// Set the path and filename to the picture
$path_picture="/www/sitename/pictures/picture1.jpg";

// Set the path and filename to the watermark picture
$path_watermark="/www/sitename/images/watermark.jpg";

// Set umask to 0 in order to not affect the file permissions during the next operation
umask(000);
$ok=shell_exec ($path_imagemagick."composite -watermark 15x70 -gravity SouthEast $path_watermark $path_picture
$path_picture");

// If shell_exec above returns 1 this mean that the operation was sucessful.
if ($ok)
{
echo "Picture Watermarked OK";
}

?>

As you can see, ImageMagick is a great tool for dynamically processing images using a PHP-enabled Web server. Try it for yourself, and see how easy automating your image manipulation tasks can be!

Copyright © 2025 Adnet Media. All Rights Reserved. XBIZ is a trademark of Adnet Media.
Reproduction in whole or in part in any form or medium without express written permission is prohibited.

More Articles

profile

WIA Profile: Leah Koons

If you’ve been to an industry event lately, odds are you’ve heard Leah Koons even before you’ve seen her. As Fansly’s director of marketing, Koons helps steer one of the fastest-growing creator platforms on the web.

Women in Adult ·
opinion

What France's New Law Means for Age Verification Worldwide

When France implemented its Security and Regulation of the Digital Space (SREN) law on April 11, it marked a pivotal moment in the ongoing global debate surrounding online safety and access to adult content.

Corey D. Silverstein ·
opinion

From Tariffs to Trends: Staying Resilient in a Shaky Online Adult Market

Whenever I check in with clients these days, I encounter the same concerns. For many, business has not quite bounced back after the typical post-holiday-season slowdown. Instead, consumers have been holding back due to the economic uncertainty around the Trump administration’s new tariffs and their impact on prices.

Cathy Beardsley ·
opinion

Optimizing Payment Strategies for High Ticket Sales

Payment processing for more expensive items, such as those exceeding $1,000 per order, can create unique challenges. For adult businesses, those challenges are magnified. Increased fraud risk, elevated chargeback ratios and heavier scrutiny from banks and processors are only the beginning.

Jonathan Corona ·
profile

WIA Profile: Lexi Morin

Lexi Morin’s journey into the adult industry began with a Craigslist ad and a leap of faith. In 2011, fresh-faced and ambitious, she was scrolling through job ads on Craigslist when she stumbled upon a listing for an assistant makeup artist.

Women In Adult ·
profile

Still Rocking: The Hun Celebrates 30 Years in the Game

In the ever-changing landscape of adult entertainment, The Hun’s Yellow Pages stands out for its endurance. As one of the internet’s original fixtures, literally nearly as old as the web itself, The Hun has functioned as a living archive for online adult content, quietly maintaining its relevance with an interface that feels more nostalgic than flashy.

Jackie Backman ·
opinion

Digital Desires: AI's Emerging Role in Adult Entertainment

The adult industry has always been ahead of the curve when it comes to embracing new technology. From the early days of dial-up internet and grainy video clips to today’s polished social media platforms and streaming services, our industry has never been afraid to innovate. But now, artificial intelligence (AI) is shaking things up in ways that are exciting but also daunting.

Steve Lightspeed ·
opinion

More Than Money: Why Donating Time Matters for Nonprofits

The adult industry faces constant legal battles, societal stigma and workplace challenges. Fortunately, a number of nonprofit organizations work tirelessly to protect the rights and well-being of adult performers, producers and industry workers. When folks in the industry think about supporting these groups, donating money is naturally the first solution that comes to mind.

Corey D. Silverstein ·
opinion

Consent Guardrails: How to Protect Your Content Platform

The adult industry takes a strong and definite stance against the creation or publication of nonconsensual materials. Adult industry creators, producers, processors, banks and hosts all share a vested interest in ensuring that the recording and publication of sexually explicit content is supported by informed consent.

Lawrence G. Walters ·
opinion

Payment Systems: Facilitator vs. Gateway Explained

Understanding and selecting the right payment platform can be confusing for anyone. Recently, Segpay launched its payment gateway. Since then, we’ve received numerous questions about the difference between a payment facilitator and a payment gateway. Most merchants want to know which type of platform best meets their business needs.

Cathy Beardsley ·
Show More