Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

iptcembed

Description

The iptcembed of Image for PHP embeds binary IPTC data into a JPEG image.

Syntax

iptcembed(
    string $iptc_data,
    string $filename,
    int $spool = 0
): string|bool

Parameters

iptc_data

The data to be written.

filename

Path to the JPEG image.

spool

Spool flag. If the spool flag is less than 2 then the JPEG will be returned as a string. Otherwise the JPEG will be printed to STDOUT.

Return

If spool is less than 2, the JPEG will be returned, or false on failure. Otherwise returns true on success or false on failure.

Examples

1 · iptc_data filename

<?

$iptc_data = 'iptc_data';
$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/jpg/2.jpg';

$return = iptcembed($iptc_data, $filename);

var_export($return);

?>
'���' . "\0" . 'JFIF' . "\0" . '' . "\0" . '`' . "\0" . '`' . "\0" . '' . "\0" . '��' . "\0" . '&Photoshop 3.0' . "\0" . '8BIM' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '
iptc_data' . "\0" . '��' . "\0" . '>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality
��' . "\0" . 'C' . "\0" . '        

 $.\' ",#(7),01444\'9=82<.342��' . "\0" . 'C            

2!!22222222222222222222222222222222222222222222222222��' . "\0" . '' . "\0" . 'd' . "\0" . 'd"' . "\0" . '��' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '    
��' . "\0" . '�' . "\0" . '' . "\0" . '' . "\0" . '}' . "\0" . '!1AQa"q2���#B��R��$3br�    
%&\'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '    
��' . "\0" . '�' . "\0" . '' . "\0" . 'w' . "\0" . '!1AQaq"2�B����    #3R�br�
$4�%�&\'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�����������������������������������������������������������������������' . "\0" . '' . "\0" . '' . "\0" . '?' . "\0" . '���(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(���'

2 · spool

<?

$iptc_data = 'iptc_data';
$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/jpg/2.jpg';
$spool = 2;

iptcembed($iptc_data, $filename, $spool);

?>
���JFIF``��&Photoshop 3.08BIM
iptc_data��>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality
��C        

 $.' ",#(7),01444'9=82<.342��C            

2!!22222222222222222222222222222222222222222222222222��dd"��    
���}!1AQa"q2���#B��R��$3br�    
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������    
���w!1AQaq"2�B����    #3R�br�
$4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�����������������������������������������������������������������������?���(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(���

3 · return

<?

$iptc_data = 'iptc_data';
$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/jpg/2.jpg';
$spool = 2;

$return = iptcembed($iptc_data, $filename, $spool);

echo PHP_EOL;
var_export($return);

?>
���JFIF``��&Photoshop 3.08BIM
iptc_data��>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality
��C        

 $.' ",#(7),01444'9=82<.342��C            

2!!22222222222222222222222222222222222222222222222222��dd"��    
���}!1AQa"q2���#B��R��$3br�    
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������    
���w!1AQaq"2�B����    #3R�br�
$4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�����������������������������������������������������������������������?���(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(���
true

4 · base64

<?

$iptc_data = 'iptc_data';
$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/jpg/2.jpg';

$return = iptcembed($iptc_data, $filename);

echo '<!doctype html>
<html>
<body>
    <img src="data:image/jpeg;base64,' . base64_encode($return) . '">
</body>
</html>';

?>
<!doctype html>
<html>
<body>
    <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/7QAmUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAppcHRjX2RhdGEA//4APkNSRUFUT1I6IGdkLWpwZWcgdjEuMCAodXNpbmcgSUpHIEpQRUcgdjYyKSwgZGVmYXVsdCBxdWFsaXR5Cv/bAEMACAYGBwYFCAcHBwkJCAoMFA0MCwsMGRITDxQdGh8eHRocHCAkLicgIiwjHBwoNyksMDE0NDQfJzk9ODI8LjM0Mv/bAEMBCQkJDAsMGA0NGDIhHCEyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMv/AABEIAGQAZAMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APn+iiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//Z">
</body>
</html>

5 · iptc_make_tag

<?

// iptc_make_tag() by Thies C. Arntzen
function iptc_make_tag($rec, $data, $value)
{
    $length = strlen($value);
    $retval = chr(0x1c)
    . chr($rec)
    . chr($data);

    if($length < 0x8000)
    {
        $retval .= chr($length >> 8)
        . chr($length & 0xff);
    }
    else
    {
        $retval .= chr(0x80)
        . chr(0x04)
        . chr(($length >> 24) & 0xff)
        . chr(($length >> 16) & 0xff)
        . chr(($length >> 8) & 0xff)
        . chr($length & 0xff);
    }

    return $retval . $value;
}

$iptc_data = '';

$iptc_array = array(
    '2#005' => 'DocumentTitle',
    '2#010' => 'Urgency',
    '2#015' => 'Category',
    '2#020' => 'Subcatagories',
    '2#040' => 'SpecialInstructions',
    '2#055' => 'CreationDate',
    '2#080' => 'AuthorByline',
    '2#085' => 'AuthorTitle',
    '2#090' => 'City',
    '2#095' => 'State',
    '2#101' => 'Country',
    '2#103' => 'OTR',
    '2#105' => 'Headline',
    '2#110' => 'Source',
    '2#115' => 'PhotoSource',
    '2#116' => 'Copyright',
    '2#120' => 'Caption',
    '2#122' => 'CaptionWriter'
);

foreach($iptc_array as $key => $value)
{
    $rec = substr($key, 0, 1);
    $data = substr($key, 2);
    $iptc_data .= iptc_make_tag($rec, $data, $value);
}

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/jpg/2.jpg';

$return = iptcembed($iptc_data, $filename);

var_export($return);

$handle = fopen($filename, "wb");

    fwrite($handle, $return);

fclose($handle);

?>
'���' . "\0" . 'JFIF' . "\0" . '' . "\0" . '`' . "\0" . '`' . "\0" . '' . "\0" . '��Photoshop 3.0' . "\0" . '8BIM' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '
DocumentTitle
' . "\0" . 'Urgency' . "\0" . 'Category' . "\0" . '
Subcatagories(' . "\0" . 'SpecialInstructions7' . "\0" . 'CreationDateP' . "\0" . 'AuthorBylineU' . "\0" . 'AuthorTitleZ' . "\0" . 'City_' . "\0" . 'Statee' . "\0" . 'Countryg' . "\0" . 'OTRi' . "\0" . 'Headlinen' . "\0" . 'Sources' . "\0" . 'PhotoSourcet' . "\0" . '    Copyrightx' . "\0" . 'Captionz' . "\0" . '
CaptionWriter��' . "\0" . '>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality
��' . "\0" . 'C' . "\0" . '        

 $.\' ",#(7),01444\'9=82<.342��' . "\0" . 'C            

2!!22222222222222222222222222222222222222222222222222��' . "\0" . '' . "\0" . 'd' . "\0" . 'd"' . "\0" . '��' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '    
��' . "\0" . '�' . "\0" . '' . "\0" . '' . "\0" . '}' . "\0" . '!1AQa"q2���#B��R��$3br�    
%&\'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '    
��' . "\0" . '�' . "\0" . '' . "\0" . 'w' . "\0" . '!1AQaq"2�B����    #3R�br�
$4�%�&\'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�����������������������������������������������������������������������' . "\0" . '' . "\0" . '' . "\0" . '?' . "\0" . '���(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(��(���'
HomeMenu