Posts Tagged with image

Displaying 1-6 of 6 results.
Resolved: Bootstrap Form File Element upload button
posted by admin on October 12, 2016
I want customize my upload file input by bootstrtap default functionalityRead more
Resolved: How to clear browser cache when re-uploading image with same filename, in php?
posted by admin on June 18, 2016
I have a listing of items, that also contains an image thumbnail. Sometimes I need to change the thumbnail image, but keep the filename the same. Is there a way to force the browser to download the newly uploaded image, instead of grabbing one from the browser cache?

This is very pertinent when people update their avatars, which causes confusion for some users, who keep seeing their old avatar, until they clear the browser cache, or restart the browser.Read more
Wiki: PHP Dominant Colour Function with GD Librarywiki
posted by admin on April 13, 2016
Someone asked if it was possible to find the dominant colour (the more frequent colour, in %) of an image.

So I read about the GD PHP Library, which enables image support. I found the interesting function imageColorAt() which the colour of a specific pixel. Hence, my function consists of resizing to a known size, 100 x 100, then looping into each pixel, storing it’s colour into an array, then sorting the array to find the more frequent key.

Here’s the result :

function getDominantColour($image, $type='jpeg') // $type can be gif, jpeg or png
// This function needs GD Library enabled

eval('$source = imagecreatefrom' . $type . '("' . $image . '");'); // we load the source image
$source_x = imagesx($source); // source's X
$source_y = imagesy($source); // source's Y
$resized_x = 100; // resized image's X
$resized_y = 100; // resized image's Y
$resized= imagecreatetruecolor($resized_x, $resized_y); // we create a blank 100 x 100 image
imagecopyresampled($resized, $source, 0, 0, 0, 0, $resized_x, $resized_y, $source_x, $source_y); // We then copy and resized the source image into the blank image

// Required vars declaration
$colours = array();
$rgb = '';
$index = array();
for ($x=0; $x<100; $x++) // We loop into the pixels X
for ($y=0; $y<100; $y++) // We loop into the pixels Y
$rgb = imagecolorat($resized, $x, $y); // get the RGB of the pixel
$index = imagecolorsforindex($resized, $rgb); // Get the RGB Index
$key = 'R' . $index['red'] . 'G' . $index['green'] . 'B' . $index['blue']; // Put it into a string
if (empty($colours[$key])) // If it's the first time this colour is encountered
$colours[$key] = 1; // We give it a value of 1
} else { // If it's not the first time it is encountered
$colours[$key]++; // We increment its value
arsort($colours, SORT_NUMERIC); // We then sort the colours array so that the first one is the most frequent one
return key($colours); // we return the most frequent value

Working with images sure is fun. Looking forward to have more functions with the GD libraryRead more
Resolved: How do I get a YouTube video thumbnail from URL or embed iframe
posted by admin on April 9, 2016
If I have a YouTube video URL, is there any way to use PHP and cURL to get the associated thumbnail from the YouTube API?Read more
Resolved: Yii Captcha Broken Image
posted by admin on March 12, 2016
The captcha image is broken (no image appearing). The other components of captcha (links, error matching code etc) seem to work correctly

In Controller:

public function actions() {
return array(
'captcha' => array(
'class' => 'CCaptchaAction',
'backColor' => 0xFFFFFF,

In View:

<?php if (CCaptcha::checkRequirements()): ?>
<div class="row">
<?php echo $form->labelEx($model, 'verifyCode'); ?>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model, 'verifyCode'); ?>
<div class="hint">Please enter the letters as they are shown in the image above.

Letters are not case-sensitive.</div>
<?php echo $form->error($model, 'verifyCode'); ?>
<?php endif; ?>

In Model:

public $verifyCode;
public function rules() {
return array(
array('verifyCode', 'captcha', 'allowEmpty' => !CCaptcha::checkRequirements()),

Why I have this problem?Read more
Resolved: CSS Perfect Full Page Background Image cover stretch fixed
posted by admin on January 31, 2016
I want to fix my background image, stretch it by width 100%Read more