Home Backend Development PHP Tutorial How to use PHP and Qiniu cloud storage interface to implement special filters and style migration of pictures

How to use PHP and Qiniu cloud storage interface to implement special filters and style migration of pictures

Jul 07, 2023 pm 01:21 PM
php filter Qiniuyun style transfer

How to use PHP and Qiniu cloud storage interface to implement special filters and style migration of pictures

Abstract: This article introduces how to use PHP and Qiniu cloud storage interface to implement special filters and styles of pictures Migration method. By using the image processing interface of Qiniu Cloud Storage, we can process various filter effects on images and transfer the style of one image to another image. In order to implement these functions, we will use Qiniu Cloud Storage’s PHP SDK.

Keywords: PHP, Qiniu Cloud Storage, image processing, filters, style migration, SDK

  1. Introduction
    With the development of the Internet, image processing technology has also changed becomes more and more important. People have increasingly higher requirements for the effects of pictures, for example, applying special filters to pictures to increase artistic effects, or transferring the style of one picture to another. In this article, we will introduce how to use PHP and Qiniu cloud storage interface to implement these functions.
  2. Preparation
    Before we start, we need to do some preparations.

First, we need to create an account on Qiniu Cloud Storage and obtain the API key. Then, we need to install the PHP SDK of Qiniu Cloud Storage, which can be installed through Composer. Open a command line terminal, enter the project directory, and execute the following command:

composer require qiniu/php-sdk
Copy after login

After the installation is complete, we can start writing code.

  1. Implementing image filter effects
    First, we will write code to implement image filter effect processing. Using the image processing interface of Qiniu Cloud Storage, you can achieve a variety of filter effects, such as sepia filters, black and white filters, etc. The following is a sample code:
<?php
require 'vendor/autoload.php'; // 引入七牛云存储的PHP SDK

use QiniuAuth; // 引入Auth类
use QiniuStorageBucketManager; // 引入BucketManager类

$accessKey = 'YOUR_ACCESS_KEY';
$secretKey = 'YOUR_SECRET_KEY';
$bucket = 'YOUR_BUCKET';

// 实例化Auth类
$auth = new Auth($accessKey, $secretKey);

// 实例化BucketManager类
$bucketManager = new BucketManager($auth);

// 图片链接
$url = 'http://example.com/image.jpg';

// 滤镜效果参数
$filter = 'filtername/arg1/arg2';

// 生成新的图片链接
$newUrl = $bucketManager->buildUrl($url, $filter);

// 输出新的图片链接
echo $newUrl;
?>
Copy after login

In the code, we first introduced the PHP SDK of Qiniu Cloud Storage and used the Require statement to introduce it as a dependent library. Then, we introduced the Auth class and BucketManager class using the Use statement. Next, we need to replace the access key and bucket name with our own information.

The core part of the code is the buildUrl() method, which accepts two parameters: image link and filter effect parameters. We can set different values ​​for the $filter variable to achieve different filter effects. After calling the buildUrl() method, we can get the processed image link.

You can change the code according to your own needs and add other filter effect parameters. After executing the code, a new image link will be output, that is, the processed image.

  1. Implement style migration
    Next, we will implement the function of migrating the style of one picture to another picture. This is a relatively complex image processing task, but the image processing interface of Qiniu Cloud Storage provides corresponding functions. The following is a sample code:
<?php
require 'vendor/autoload.php'; // 引入七牛云存储的PHP SDK

use QiniuAuth; // 引入Auth类
use QiniuStorageBucketManager; // 引入BucketManager类

$accessKey = 'YOUR_ACCESS_KEY';
$secretKey = 'YOUR_SECRET_KEY';
$bucket = 'YOUR_BUCKET';

// 实例化Auth类
$auth = new Auth($accessKey, $secretKey);

// 实例化BucketManager类
$bucketManager = new BucketManager($auth);

// 原始图片链接
$fromUrl = 'http://example.com/image1.jpg';

// 目标图片链接
$toUrl = 'http://example.com/image2.jpg';

// 风格迁移参数
$style = 'yourStyle';

// 生成新的图片链接
$newUrl = $bucketManager->buildUrl($fromUrl, 'style/' . $style . '|saveas/' . Qiniuase64_urlSafeEncode($bucket . ':' . $toUrl));

// 输出新的图片链接
echo $newUrl;
?>
Copy after login

The code is similar to the previous filter effect processing example, except that the parameters for saving the target image are added to the buildUrl() method. We pass the link of the original image and the link of the target image to the buildUrl() method, and set the corresponding style migration parameters.

According to your own needs, you can change the variable values ​​in the code and add other style migration parameters. After executing the code, the processed image link will be output, that is, the image after style migration.

  1. Summary
    Through the introduction of this article, we have learned how to use PHP and Qiniu cloud storage interface to implement special filters and style migration of pictures. Using the image processing interface of Qiniu Cloud Storage, we can easily achieve various processing effects on images, thereby increasing the artistic effect of the images. By calling the corresponding methods and setting parameters according to our own needs, we can implement special filters and style migration of pictures to make the pictures more vivid and interesting.

Reference materials:

  • Qiniu Cloud Storage Documentation: https://developer.qiniu.com/dora

The above code examples It is implemented through the PHP SDK of Qiniu Cloud Storage. Qiniu Cloud Storage has powerful image processing functions. By calling the corresponding methods and setting parameters, we can achieve various filter effects and style migration. Readers can modify and expand according to their own needs to achieve more creative and unique image processing effects.

The above is the detailed content of How to use PHP and Qiniu cloud storage interface to implement special filters and style migration of pictures. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

See all articles