Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong encoding when getting metadata form image with exif_read_data

Tags:

html

php

encoding

I'm getting the 'Comments' information from a uploaded image with the exif_read_data function. I want to insert this information into the corresponding image 'alt' tag. The inserted value looks like this: T�r�a�v�e�l���

I tried several encoding variants but i can't get a proper string.

PHP:

$exif = exif_read_data($dir.$image , 0 ,true);
$rel  = $exif["IFD0"]["Comments"];

HTML:

<img alt='$rel' src='test.jpg' />

OUTPUT: something like this...

<img alt='T�r�a�v�e�l��� ' src='test.jpg' />

The actual encoding for the html page is UTF-8

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
like image 331
Steven Web Avatar asked Jun 19 '26 18:06

Steven Web


1 Answers

I don't know if will solve your problem (if yes, let me know here). But there's a comment at php.net with a php.ini config to set the exif encoding:

<?php
ini_set('exif.encode_unicode', 'UTF-8');
?>
like image 154
saulotoledo Avatar answered Jun 22 '26 08:06

saulotoledo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!