mirror of
https://github.com/php/doc-es.git
synced 2026-04-24 15:48:13 +02:00
9e21bcd7df
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@336400 c90b9560-bf6c-de11-be94-00142212c4b1
160 lines
4.2 KiB
XML
160 lines
4.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 18dc6d0d465c80989566e19e68e1a9ff43dca9cf Maintainer: seros Status: ready -->
|
|
<!-- Reviewed: no Maintainer: seros -->
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="imagick.getimagehistogram">
|
|
<refnamediv>
|
|
<refname>Imagick::getImageHistogram</refname>
|
|
<refpurpose>Obtiene el histograma de la imagen</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>Imagick::getImageHistogram</methodname>
|
|
<void/>
|
|
</methodsynopsis>
|
|
<para>
|
|
Devuelve el histograma de la imagen como un array de objetos ImagickPixel.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Devuelve el histograma de la imagen como un array de objetos ImagickPixel.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
&imagick.imagick.throws;
|
|
</para>
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Generates <function>Imagick::getImageHistogram</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function getColorStatistics($histogramElements, $colorChannel) {
|
|
$colorStatistics = [];
|
|
|
|
foreach ($histogramElements as $histogramElement) {
|
|
$color = $histogramElement->getColorValue($colorChannel);
|
|
$color = intval($color * 255);
|
|
$count = $histogramElement->getColorCount();
|
|
|
|
if (array_key_exists($color, $colorStatistics)) {
|
|
$colorStatistics[$color] += $count;
|
|
}
|
|
else {
|
|
$colorStatistics[$color] = $count;
|
|
}
|
|
}
|
|
|
|
ksort($colorStatistics);
|
|
|
|
return $colorStatistics;
|
|
}
|
|
|
|
|
|
|
|
function getImageHistogram($imagePath) {
|
|
|
|
$backgroundColor = 'black';
|
|
|
|
$draw = new \ImagickDraw();
|
|
$draw->setStrokeWidth(0); //hacer que las líneas sean lo más finas posibles
|
|
|
|
$imagick = new \Imagick();
|
|
$imagick->newImage(500, 500, $backgroundColor);
|
|
$imagick->setImageFormat("png");
|
|
$imagick->drawImage($draw);
|
|
|
|
$histogramWidth = 256;
|
|
$histogramHeight = 100; // the height for each RGB segment
|
|
|
|
$imagick = new \Imagick(realpath($imagePath));
|
|
//Hacer la imagen pequeña, de lo contrario PHP tiende a quedarse sin memoria
|
|
//Esto podría conducir a resultados erróneos con imágenes que estén patológicamente 'pixeladas'
|
|
$imagick->adaptiveResizeImage(200, 200, true);
|
|
$histogramElements = $imagick->getImageHistogram();
|
|
|
|
$histogram = new \Imagick();
|
|
$histogram->newpseudoimage($histogramWidth, $histogramHeight * 3, 'xc:black');
|
|
$histogram->setImageFormat('png');
|
|
|
|
$getMax = function ($carry, $item) {
|
|
if ($item > $carry) {
|
|
return $item;
|
|
}
|
|
return $carry;
|
|
};
|
|
|
|
$colorValues = [
|
|
'red' => getColorStatistics($histogramElements, \Imagick::COLOR_RED),
|
|
'lime' => getColorStatistics($histogramElements, \Imagick::COLOR_GREEN),
|
|
'blue' => getColorStatistics($histogramElements, \Imagick::COLOR_BLUE),
|
|
];
|
|
|
|
$max = array_reduce($colorValues['red'] , $getMax, 0);
|
|
$max = array_reduce($colorValues['lime'] , $getMax, $max);
|
|
$max = array_reduce($colorValues['blue'] , $getMax, $max);
|
|
|
|
$scale = $histogramHeight / $max;
|
|
|
|
$count = 0;
|
|
foreach ($colorValues as $color => $values) {
|
|
$draw->setstrokecolor($color);
|
|
|
|
$offset = ($count + 1) * $histogramHeight;
|
|
|
|
foreach ($values as $index => $value) {
|
|
$draw->line($index, $offset, $index, $offset - ($value * $scale));
|
|
}
|
|
$count++;
|
|
}
|
|
|
|
$histogram->drawImage($draw);
|
|
|
|
header( "Content-Type: image/png" );
|
|
echo $histogram;
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|