Quantcast
Channel: Average Image Color in php for png/jpeg - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Average Image Color in php for png/jpeg

$
0
0

I want to calculate the average color of an image (png or jpg) in php.

I want a little script that will go fast to calculate the average color.

I tried by resizing an image to 1px by 1px but I didn't have success. I always have an error like this : imagesx() expects parameter 1 to be resource, string given in

Here is my php:

$post_thumb   = wp_get_attachment_url( get_post_thumbnail_id() );   $img = $post_thumb;$x = imagesx($img);$y = imagesy($img);$tmp_img = ImageCreateTrueColor(1,1);ImageCopyResampled($tmp_img,$img,0,0,0,0,1,1,$x,$y);$rgb = ImageColorAt($tmp_img,0,0);

I know it comes from my image var but I don't know how to resolve it...


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images