PHP GD Use one image to mask another image, including transparency

Matt, If you make your png with the oval white fill on black background instead of black fill with transparent background the following function does it. <?php // Load source and mask $source = imagecreatefrompng( ‘1.png’ ); $mask = imagecreatefrompng( ‘2.png’ ); // Apply mask to source imagealphamask( $source, $mask ); // Output header( “Content-type: … Read more

How do I resize pngs with transparency in PHP?

From what I can tell, you need to set the blending mode to false, and the save alpha channel flag to true before you do the imagecolorallocatealpha() <?php /** * https://stackoverflow.com/a/279310/470749 * * @param resource $image * @param int $newWidth * @param int $newHeight * @return resource */ public function getImageResized($image, int $newWidth, int $newHeight) … Read more

Troubles with Docker + PHP7 + GD resulting in “Call to undefined function imagecreatefromjpeg()”

PHP 7.4 (Alpine) If anybody is struggling to enable JPEG support in GD with PHP 7.4, here’s what I had to do in order to be able to use imagecreatefromjpeg() function. My example is based on Alpine 3.10, if you’re using other distribution adjust it to your needs. First install dependencies, in my case beside … Read more

Can I detect animated gifs using php and gd?

While searching for a solution to the same problem I noticed that the php.net site has a follow-up to the code Davide and Kris are referring to, but, according to the author, less memory-intensive, and possibly less disk-intensive. I’ll replicate it here, because it may be of interest. source: http://www.php.net/manual/en/function.imagecreatefromgif.php#88005 function is_ani($filename) { if(!($fh = … Read more

php imagecopyresized vs imagecopyresampled vs imagecopy pros/cons

imagecopyresized will copy and scale and image. This uses a fairly primitive algorithm that tends to yield more pixelated results. imagecopyresampled will copy and scale and image, it uses a smoothing and pixel interpolating algorithm that will generally yield much better results then imagecopyresized at the cost of a little cpu usage. imagecopy will copy … Read more

Crop image in PHP

If you are trying to generate thumbnails, you must first resize the image using imagecopyresampled();. You must resize the image so that the size of the smaller side of the image is equal to the corresponding side of the thumb. For example, if your source image is 1280x800px and your thumb is 200x150px, you must … Read more

install php70-gd on ubuntu

PHP7 packages for Ubuntu including php7.0-gd can be installed via PPA for PHP by Ondřej Surý: sudo add-apt-repository ppa:ondrej/php sudo apt-get update Next, install the desired version: sudo apt-get install php7.0-gd # or sudo apt-get install php7.1-gd # or sudo apt-get install php7.2-gd # or sudo apt-get install php7.3-gd # or sudo apt-get install php7.4-gd … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)