Jump to content

[SOLVED] Need some help (GD library)


slpctrl

Recommended Posts

<?php
function getpixels($pic){
$image = imagecreatefromjpeg($pic);
list($width, $height) = getimagesize($pic);
$height = $height/2;
$vars = array();
for ($i=0; $i<=$width; $i++){
  $color = imagecolorat($image, $i, $height);
  array_push($vars, $color);
  return $vars;
}
}
$pixls = getpixels("world.jpg");
foreach($pixls as $pixl){
echo "$pixl<br />";
}
?>

 

What I was trying to do here was to get the hex color code of each pixel across an image, but the code returns numbers like this: "162486" which clearly isn't any hex color codes. How can I modify this to return the hex color value of each pixel?

Link to comment
https://forums.phpfreaks.com/topic/143288-solved-need-some-help-gd-library/
Share on other sites

Never mind, I just put the return vars in the wrong spot. This does it:

 

<?php
function getpixels($pic){
$image = imagecreatefromjpeg($pic);
list($width, $height) = getimagesize($pic);
$height = $height/2;
$vars = array();
for ($i=0; $i<=$width; $i++){
  $color = imagecolorat($image, $i, $height);
  array_push($vars, $color);
}
return $vars;
}
$pixls = getpixels("world.jpg");
foreach($pixls as $pixl){
echo "$pixl<br />";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.