What should I do if the php image displays garbled characters?

藏色散人
Release: 2023-03-13 18:48:01
Original
4126 people have browsed it

The solution to the problem that php pictures display garbled characters: 1. Open the corresponding PHP code file; 2. Add "header("Content-Type:image/jpg");" to the header of the page to declare the picture. Just type.

What should I do if the php image displays garbled characters?

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php picture shows a garbled code what to do?

The picture displays garbled characters:

Just add the following code to the head of the page, which is used to declare the picture type.


        
Copy after login

Attachment:

PHP adds encoding to pictures

function setWater($dst_path, $save_path, $text) { // 创建图片的实例 $dst = imagecreatefromstring(file_get_contents($dst_path)); // 文字样式 $font = realpath('./font/arial.ttf'); $black = imagecolorallocate($dst, 255, 255, 255); //字体颜色 // 加文字 imagefttext($dst, 22, 0, 20, 40, $black, $font, $text); // 输出图片 list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path); switch ($dst_type) { //GIF case 1: //header('Content-Type: image/gif'); $save_path = $save_path . $text .'.gif'; imagegif($dst, $save_path, 90); break; //JPG case 2: //header('Content-Type: image/jpeg'); $save_path = $save_path . $text .'.jpg'; imagejpeg($dst, $save_path, 90); break; //PNG case 3: //header('Content-Type: image/png'); $save_path = $save_path . $text .'.png'; imagepng($dst, $save_path, 90); break; default: break; } imagedestroy($dst); } $dst_path = '7002.jpg'; //$text = '7001'; //setWater($dst_path, './tmppic/', $text); for ($i=1; $i<=240; $i++) { $text = '00'. $i; $text = substr($text, -3); setWater($dst_path, './tmppic/', $text); } echo('ok');
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if the php image displays garbled characters?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!