To work with PS images in PHP, you can use the GD library – a commonly used library for image manipulation in PHP. Here is a simple example:
Check whether the GD library is installed and enabled. You can search for "gd" in the php.ini file to determine if this library is enabled. If it is not enabled, please enable it and then restart the web server.
Create an image object from a file. Use the following function to create an image object from a file:
$image = imagecreatefromjpeg("image.jpg"); // 从JPEG文件创建 $image = imagecreatefrompng("image.png"); // 从PNG文件创建 $image = imagecreatefromgif("image.gif"); // 从GIF文件创建- Image processing: The following functions can be used to process images:
- imagecopyresampled: Scale and crop images
- Image Filter: Add effects such as blur or grayscale conversion.
- imagefilledrectangle: Draw a shape on an image
- imagettftext: Add text to image
- Output Image: The final step is to display the processed image in a browser or save it as a file. Here are some available functions:
- header('Content-Type: image/png'); imagepng($image); // Output the PNG image to the browser
- imagepng($image, "output.png"); // Save the PNG image as a file
Hope this information is helpful to you!