Для получения полного доступа
зарегистрируйтесь.
Сниппет,  PHP

Base64 encoded image data to image file


/**
 * Create image file from base64 image data
 * @param string $filename Path to the file where to write the data.
 * @param string $data The base64 image data
 * @return bool True when created | False anyway
 */
function imgBase64ToFile ( string $filename, string $data ) {
	list(, $data) = explode(';', $data);
	list(, $data) = explode(',', $data);
	$data = base64_decode($data);
	return file_put_contents($filename, $data) !== false;
}

/************
 * EXAMPLE
 ***********/
$base64Data = <<<BASE64
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAGrUlEQVR42uzceWwUdRjGcUSg3BVo5FQqIEVb1KgQkFCQy6hEiSCCSggqlyJRYzgMEm8iJpXDGNGImphIUJZCKGqqoCbcRiERUS6jqK1SkbMFgb5+/9g/Jj9mdjql2233fZ/kk5C2bJp3nu3MzvxmGoiIUUz9ALRTPwDt1A9AO/UD0E79ALRTPwDt1A9AO/UD0E79ALRTPwDt1A9AO/UD0E79ALRTPwDt1A9AO/UD0E79ALRTPwDt1A9AO/UD0E79ALRTPwDt1A9AO/UD0E79ALRTPwDt1A9AO/UD0E79ALRTPwDt1A9AO/UD0E79ALRTPwDt1A9AO/UD0E79ALRTPwDt1A9AO/UD0E79ALRTPwDtkvridSQZaIeuyEUfDMQQjAD4N19DH+SiK9ohA6mOFaAKaYxsDMV0FCCGrdiPMpSjEhKiEhUowwFsw2q8jscwHN3QxAqQugJchoGYhVX4GeWQWlKBvYhhDgahjRUguQXojimI4U9IHVOCNZiOq60AqIF0wGQUoxxST1RgA6ahkxUgevpgGQ5DatBbmO9RgPOQJPoH76KfFSA8A1GISkgNO46W8OYGSC1ah1utABfmGqyAJNFOXAJvHoekwCr0tgLw8Q3P4AQkyT6Em/cgKVKO55ChtQA5+BpSS56Cm28hKbYZudoKcDv+htSioT6fMM5C6oAjuFtLAR6IMPgXMRpj/Hi+NwFzEcMRiKMcXeBNps9rjcVDmI81OApxfFrF32k8ZuId7IOEOI+H0r0AYyIc4Z9FZ0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k4igkhebDzVpIDdmCPM03hszDSQg2odhjCyTFdqPYcbKGbgx5Hhl2a1iDBtdiJUSJGK6zW8MuTD7WoBKShoowxG4ODU9fvI0ySD13BMvR324Pj56OmIovUAGpJ05jIx5FZ3tARM2kB6ahECWQOqYUa/EoetojYpL/kKh8zEYMe1FRy+/wfSjEXAxGW3tIlKMW0wRXYTgew+tYjW04gDJURDi4rMA/OIjtKMQizMAIdEeGPSau/jwoMgvZyENf5GMYRsQNQ378e3nIRhaa2oMijT0q1lgBjBXAWAGMFcBYAYwVwFgBjBXAWAGMFcBYAYwVwFgBjBXAWAGMFcBYAYwVwFgBjBXAWAGMFcBYAYwVwFgBjBXAWAGMFcBYAYwVwFgBjBXAWAH+b5cOCQAAAAAE/X/tChuBByAAAiAAAiAAAiAAAjAL4Vh9E/WkOccAAAAASUVORK5CYII=
BASE64;

imgBase64ToFile('image.png', $base64Data);
  php image

Автор


Gravatar image
blacksmoke26
  • Репутация: 13
  • Сниппеты : 11
  • Ревизии : 0
Подписаться

Чтобы увидеть комментарии, нужно быть участником сообщества

Регистрация