iptcembed

(PHP 4, PHP 5, PHP 7, PHP 8)

iptcembedIncorpora datos binarios IPTC en una imagen JPEG

Descripción

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

iptcembed() incorpora datos binarios IPTC en una imagen JPEG.

Parámetros

iptc_data

Los datos a escribir.

filename

Ruta hacia el fichero JPEG.

spool

El flag de la bobina. Si la bobina es inferior a 2, entonces el fichero JPEG será devuelto en forma de string. De lo contrario el fichero JPEG será enviado a STDOUT.

Valores devueltos

Si spool es inferior a 2, el fichero JPEG será devuelto, o false si ocurre un error. De lo contrario devuelve true en caso de éxito o false si ocurre un error.

Ejemplos

Ejemplo #1 Ejemplo con iptcembed()

<?php

// Función iptc_make_tag() por 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;
}

// Ruta hacia el fichero JPEG
$path = './phplogo.jpg';

// Define las etiquetas IPTC
$iptc = array(
    '2#120' => 'Test image',
    '2#116' => 'Copyright 2008-2009, The PHP Group'
);

// Conversión de las etiquetas IPTC a código binario
$data = '';

foreach($iptc as $tag => $string)
{
    $tag = substr($tag, 2);
    $data .= iptc_make_tag(2, $tag, $string);
}

// Incorporación de los datos IPTC
$content = iptcembed($data, $path);

// Escribe los datos de la nueva imagen en un fichero.
$fp = fopen($path, "wb");
fwrite($fp, $content);
fclose($fp);
?>

Notas

Nota: Esta función no requiere la biblioteca GD.