Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Image attribute processing by Grafika in PHP

Shulou Source: shulou.com Published: 2022-06-02 19:32:04 09月30日 Update

This article mainly shows you the "PHP Grafika how to achieve image attribute processing", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to achieve image attribute processing in PHP Grafika" this article.

1. Output the picture in binary format

The purpose of this method is to open a picture, then format it into binary data, and output it directly to the browser, rather than the traditional src display image.

It has a parameter that allows you to customize the format of the output image, such as png.

We open the picture here and output it as png.

Of course, you still have to tell the browser that the type of output you need is header ('Content-type: image/png').

Use Grafika\ Grafika; $editor = Grafika::createEditor (); $editor- > open ($image, 'yanying-smaller.jpg'); header (' Content-type: image/png'); / / Tell the browser we're sending a png image $image- > blob ('PNG')

2. Get the processing library currently used by the image

Use the method to get and process the current picture. What library does grafika use, gd or Imagick?

This method is not in editor, but directly in $image without any parameters.

Use Grafika\ Grafika; $editor = Grafika::createEditor (); $editor- > open ($image, 'yanying-smaller.jpg'); $result = $image- > getCore (); var_dump ($result); / / resource (12, gd)

3. Get the height of the picture

The height of our picture is 213px

Use Grafika\ Grafika; $editor = Grafika::createEditor (); $editor- > open ($image, 'yanying-smaller.jpg'); $result = $image- > getHeight (); var_dump ($result); / / int 213

4. Get the picture width

Our picture width is 319px.

Use Grafika\ Grafika; $editor = Grafika::createEditor (); $editor- > open ($image, 'yanying-smaller.jpg'); $result = $image- > getWidth (); var_dump ($result); / / int 319

5. Get the picture name

The picture name is the current file name

Use Grafika\ Grafika; $editor = Grafika::createEditor (); $editor- > open ($image, 'yanying-smaller.jpg'); $result = $image- > getImageFile (); var_dump ($result); / / string' yanying-smaller.jpg' (length=19)

6. Get the picture type

Here, we found that it belongs to jpg.

Use Grafika\ Grafika; $editor = Grafika::createEditor (); $editor- > open ($image, 'yanying-smaller.jpg'); $result = $image- > getType (); var_dump ($result); / / string' JPEG' (length=4)

7. Determine whether the picture is dynamic, such as gif

Our picture is jpg, so it is not a dynamic image. The return value is bool, true or false.

Use Grafika\ Grafika; $editor = Grafika::createEditor (); $editor- > open ($image, 'yanying-smaller.jpg'); $result = $image- > isAnimated (); var_dump ($result); / / above are all the contents of the article "how Grafika implements image attribute processing in PHP". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Picture processing output format image property content method article type binary dynamic parameter name width browser or height learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn Apple Shulou Tech Info NVidia