function image_resize_sepia(&$src_im, $quality = 60)
{
    $src_x = ceil(imagesx($src_im));
    $src_y = ceil(imagesy($src_im));
    $dst_x = $src_x;
    $dst_y = $src_y;
    $dst_im = ImageCreateTrueColor($dst_x, $dst_y);
    ImageAntiAlias($dst_im, TRUE);
    ImageCopyResampled($dst_im, $src_im, 0, 0, 0, 0, $dst_x, $dst_y, $src_x, $src_y);
    // Change style of image pixelwise
    for ($y = 0; $y < $dst_y; $y++) {
        for ($x = 0; $x < $dst_x; $x++) {
            $col = ImageColorAt($dst_im, $x, $y);
            $r = ($col & 0xff0000) >> 16;
            $g = ($col & 0xff00) >> 8;
            $b = $col & 0xff;
            $grey = (min($r, $g, $b) + max($r, $g, $b)) / 2;
            // Boost  colors
            $boost = 1.2;
            $boostborder = 250;
            for ($i = 0; $i < 25; $i++) {
                if ($grey > $boostborder) {
                    $grey = $grey * $boost;
                    break;
                }
                $boost -= 0.01;
                $boostborder -= 10;
            }
            // Set sepia palette
            $r = $grey * 1.01;
            $g = $grey * 0.98;
            $b = $grey * 0.9;
            // Correct max values
            $r = $r > 255 ? 255 : $r;
            $g = $g > 255 ? 255 : $g;
            $b = $b > 255 ? 255 : $b;
            $col = ImageColorAllocate($dst_im, $r, $g, $b);
            ImageSetPixel($dst_im, $x, $y, $col);
        }
    }
    $src_im = $dst_im;
}
Example #2
0
 public function _createRouteImage($path)
 {
     $encoded = json_decode($this->points)->points;
     $distance = $this->distance;
     $im_width = 100;
     $im_height = 100;
     $padding = 0.85;
     $point_arr = $this->_decodePolylineToArray($encoded);
     $bg = imagecreatefrompng(PUBLIC_ROOT . "/img/earth.png");
     $im = imagecreatetruecolor($im_width, $im_height) or die('Cannot Initialize new GD image stream');
     imageSaveAlpha($bg, true);
     ImageAlphaBlending($im, true);
     ImageAntiAlias($im, true);
     $black = imagecolorallocatealpha($im, 0x0, 0x0, 0x0, 0);
     $clear = imagecolorallocatealpha($im, 200, 200, 200, 127);
     $line_color = imagecolorallocatealpha($im, "0x00", "0x3c", "0xff", 0);
     imagefill($im, 0, 0, $clear);
     $boundingBox = $this->_getBoundingBox($point_arr);
     $height = $boundingBox["height"];
     $width = $boundingBox["width"];
     $height = $width = max(array($height, $width));
     $center_point = $boundingBox["center"];
     $normal_points = array();
     $normal_scaled = array();
     $i = 0;
     while ($i < count($point_arr["x"])) {
         $x_dist = $point_arr["x"][$i] - $center_point["x"];
         $y_dist = $point_arr["y"][$i] - $center_point["y"];
         $x_norm = $x_dist / $width * $padding;
         $y_norm = $y_dist / $height * $padding;
         $normal_points[] = array("x" => $x_norm, "y" => $y_norm);
         $x_scaled = ($x_norm + 1) * $im_width / 2;
         $y_scaled = ($y_norm + 1) * $im_height / 2;
         $normal_scaled[] = array("x" => $x_scaled, "y" => $y_scaled);
         $i++;
     }
     for ($i = 1; $i < count($normal_points); $i++) {
         imageline($im, $normal_scaled[$i - 1]["x"], $normal_scaled[$i - 1]["y"], $normal_scaled[$i]["x"], $normal_scaled[$i]["y"], $line_color);
     }
     //imagestring($im, 3, $im_width * 0.3, $im_height * 0.75, $distance." mi", $black);
     // The text to draw
     //$text = 'Testing...';
     // Replace path by your own font path
     $font = PUBLIC_ROOT . "/font/arial.ttf";
     // Add some shadow to the text
     imagettftext($im, 10, 0, $im_width * 0.05, $im_height * 0.95, $black, $font, $distance . " mi");
     imagecopy($bg, $im, 0, 0, 0, 0, $im_width, $im_height);
     //imagecopy($shadow, $bg, 7, 6, 0, 0, $im_width, $im_height);
     $result = imagepng($bg, $path);
     imagedestroy($im);
     imagedestroy($bg);
     return $result;
 }
function trial_display($participant, $current_trial, $source_image_dir, $output_dir)
{
    // connect to db
    $username = "******";
    $password = "";
    mysql_connect(localhost, $username, $password) or die("Can't find databse!");
    //Create Canvas
    $myImage = ImageCreateTrueColor(1024, 768);
    ImageAntiAlias($myImage, true);
    imagesetthickness($myImage, 2);
    //Define Colors, First Color is BG Color
    $background = ImageColorAllocate($myImage, 255, 255, 255);
    $red = ImageColorAllocate($myImage, 255, 0, 0);
    $blue = ImageColorAllocate($myImage, 0, 0, 255);
    $green = ImageColorAllocate($myImage, 0, 255, 0);
    $white = ImageColorAllocate($myImage, 255, 255, 255);
    $black = ImageColorAllocate($myImage, 0, 0, 0);
    $purple = ImageColorAllocate($myImage, 255, 165, 0);
    #this is really orange
    $teal = ImageColorAllocate($myImage, 100, 255, 255);
    $gray = ImageColorAllocate($myImage, 255, 255, 153);
    $pink = ImageColorAllocate($myImage, 255, 0, 204);
    // draw the background
    imagefilledrectangle($myImage, 0, 0, 1024, 768, $background);
    $ias = mysql_query("SELECT * FROM " . $current_project . ".aois WHERE trial_index='" . $current_trial . "' AND ppt_id='" . $participant . "'");
    #echo "SELECT * FROM ".$current_project.".aois WHERE trial_index=".$current_trial." AND ppt_id='".$participant."'";
    if (mysql_error()) {
        echo mysql_error();
    }
    while ($row_ia = mysql_fetch_array($ias)) {
        $x = $row_ia['X_1'];
        $y = $row_ia['Y_1'];
        $x2 = $row_ia['X_2'];
        $y2 = $row_ia['Y_2'];
        $image_name = $row_ia['image_name'];
        $object = imagecreatefromjpeg($source_image_dir . "\\" . $image_name . ".jpg");
        imagecopymerge($myImage, $object, $x, $y, 0, 0, 50, 50, 80);
        imagerectangle($myImage, $x, $y, $x2, $y2, $purple);
    }
    $result = mysql_query("SELECT * FROM " . $current_project . "." . $participant . " WHERE trial_index=" . $current_trial . "") or die("FFS");
    $row_count = 1;
    while ($row = mysql_fetch_array($result)) {
        $current_x = $row['CURRENT_FIX_X'];
        $current_y = $row['CURRENT_FIX_Y'];
        $next_x = $row['NEXT_FIX_X'];
        $next_y = $row['NEXT_FIX_Y'];
        $last_x = $row['PREVIOUS_FIX_X'];
        $last_y = $row['PREVIOUS_FIX_Y'];
        $fix_index = $row['CURRENT_FIX_INDEX'];
        $trial_index = $row['TRIAL_INDEX'];
        $current_fix_start = $row['CURRENT_FIX_START'];
        $current_fix_end = $row['CURRENT_FIX_END'];
        $current_fix_duration = $row['CURRENT_FIX_DURATION'];
        $before_any = $row['BEFORE_ANY'];
        $interruption_sac = $row['INTERRUPTION_SAC'];
        $after_any = $row['AFTER_ANY'];
        $interruption_duration = $after_any - $interruption_sac;
        $before_time = $interruption_sac - $before_any;
        $header_string = "Participant: " . $participant . " Trial " . $trial_index . " Duration:" . $interruption_duration . " Before Time:" . $before_time;
        if ($row_count == 1) {
            #bool imagefilledrectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )
            imagefilledrectangle($myImage, 0, 0, 1024, 30, $gray);
            imagettftext($myImage, 12, 0, 20, 20, $black, "C:/windows/fonts/arial.ttf", $header_string);
        }
        $row_count = $row_count + 1;
        // before period
        if ($current_fix_start < $interruption_sac && $current_fix_end < $interruption_sac) {
            $set_colour = $red;
        }
        // interruption period  : PURE INTERRUPTION
        if ($current_fix_start > $interruption_sac && $current_fix_end > $interruption_sac && $current_fix_start < $after_any && $current_fix_end < $after_any) {
            $set_colour = $blue;
        }
        // inter/after period
        if ($current_fix_start > $interruption_sac && $current_fix_end > $interruption_sac && $current_fix_start < $after_any && $current_fix_end > $after_any) {
            $set_colour = $pink;
        }
        // after period
        if ($current_fix_start > $after_any && $current_fix_end > $after_any) {
            $set_colour = $green;
        }
        ImageLine($myImage, $last_x, $last_y, $current_x, $current_y, $set_colour);
        imagettftext($myImage, 10, 0, $current_x + 10, $current_y, $set_colour, "C:/windows/fonts/arial.ttf", $fix_index);
        imagettftext($myImage, 10, 0, $current_x + 10, $current_y + 13, $set_colour, "C:/windows/fonts/arial.ttf", $current_fix_duration);
    }
    Imagejpeg($myImage, $output_dir . "/" . $participant . "_" . $current_trial . ".jpg", 100);
    ImageDestroy($myImage);
}
Example #4
0
function Image_Resize($Source, $Width, $Height)
{
    /****************************************************************************/
    $__args_types = array('string', 'integer');
    #-----------------------------------------------------------------------------
    $__args__ = Func_Get_Args();
    eval(FUNCTION_INIT);
    /****************************************************************************/
    if (!Function_Exists('ImageCreateFromString')) {
        return ERROR | Trigger_Error('[Image_Resize]: модуль работы с изображениями не установлен');
    }
    #-----------------------------------------------------------------------------
    $Real = @ImageCreateFromString($Source);
    if (!Is_Resource($Real)) {
        return ERROR | @Trigger_Error("[Image_Resize]: не возможно создать изображение");
    }
    #-----------------------------------------------------------------------------
    if (Function_Exists('imageantialias')) {
        ImageAntiAlias($Real, TRUE);
    }
    #-----------------------------------------------------------------------------
    $Result = ImageCreateTrueColor($Width, $Height);
    if (!$Result) {
        return ERROR | @Trigger_Error('[Image_Resize]: не удалось создать пустое изображение');
    }
    #-----------------------------------------------------------------------------
    $White = ImageColorAllocate($Result, 230, 230, 230);
    #-----------------------------------------------------------------------------
    if (!ImageFill($Result, 0, 0, $White)) {
        return ERROR | @Trigger_Error('[Image_Resize]: не удалось закрасить изображение');
    }
    #-----------------------------------------------------------------------------
    $Sx = @ImageSx($Real);
    if (!$Sx) {
        return ERROR | @Trigger_Error("[Image_Resize]: не возможно получить ширину изображения");
    }
    #-----------------------------------------------------------------------------
    $Sy = @ImageSy($Real);
    if (!$Sy) {
        return ERROR | @Trigger_Error("[Image_Resize]: не возможно получить высоту изображения");
    }
    #-----------------------------------------------------------------------------
    $Folder = System_Element('tmp');
    if (Is_Error($Folder)) {
        return ERROR | @Trigger_Error('[Image_Resize]: не удалось найти временную папку');
    }
    #-----------------------------------------------------------------------------
    if ($Width < $Sx || $Height < $Sy) {
        #---------------------------------------------------------------------------
        $HW = $Sy / $Sx;
        $WH = $Sx / $Sy;
        #---------------------------------------------------------------------------
        $WNew = $Width;
        $HNew = $Height;
        #---------------------------------------------------------------------------
        if ($Sx < $Sy) {
            $HNew = (int) ($WNew * $HW);
        } else {
            $WNew = (int) ($HNew * $WH);
        }
        #---------------------------------------------------------------------------
        if (!Preg_Match('/no\\sconvert/', Exec('which convert'))) {
            #-------------------------------------------------------------------------
            $File = SPrintF('%s/%s', $Folder, UniqID('Image'));
            #-------------------------------------------------------------------------
            if (!ImageJpeg($Real, $File, 100)) {
                return ERROR | @Trigger_Error('[Image_Resize]: не удалось сохранить временное изображение');
            }
            #-------------------------------------------------------------------------
            $Command = SPrintF('convert %s -thumbnail %ux%u^ -gravity North -extent %ux%u %s', $File, $Width, $Height, $Width, $Height, $File);
            #-------------------------------------------------------------------------
            Debug($Command);
            #-------------------------------------------------------------------------
            if (Exec($Command, $Log)) {
                return ERROR | @Trigger_Error(SPrintF("[Image_Resize]: ошибка выполнения команды:\n%s", Implode("\n", $Log)));
            }
            #-------------------------------------------------------------------------
            $Result = IO_Read($File);
            if (Is_Error($Result)) {
                return ERROR | @Trigger_Error('[Image_Resize]: не удалось прочитать изображение');
            }
            #-------------------------------------------------------------------------
            if (!UnLink($File)) {
                return ERROR | @Trigger_Error('[Image_Resize]: не удалось удалить временный файл');
            }
            #-------------------------------------------------------------------------
            return $Result;
        } else {
            #-------------------------------------------------------------------------
            if (!ImageCopyResized($Result, $Real, 0, 0, 0, 0, $WNew, $HNew, $Sx, $Sy)) {
                return ERROR | @Trigger_Error('[Image_Resize]: не удалось уменьшить изображение');
            }
        }
    } else {
        #---------------------------------------------------------------------------
        if (!ImageCopy($Result, $Real, ($Width - $Sx) / 2, ($Height - $Sy) / 2, 0, 0, $Sx, $Sy)) {
            return ERROR | @Trigger_Error('[Image_Resize]: не удалось уменьшить изображение');
        }
    }
    #-----------------------------------------------------------------------------
    $File = SPrintF('%s/%s', $Folder, UniqID('Image'));
    #-----------------------------------------------------------------------------
    if (!ImageJpeg($Result, $File, 95)) {
        return ERROR | @Trigger_Error('[Image_Resize]: не удалось сохранить временное изображение');
    }
    #-----------------------------------------------------------------------------
    if (!ImageDestroy($Result)) {
        return ERROR | @Trigger_Error('[Image_Resize]: не удалось освободить ресурс изображения');
    }
    #-----------------------------------------------------------------------------
    $Result = IO_Read($File);
    if (Is_Error($Result)) {
        return ERROR | @Trigger_Error('[Image_Resize]: не удалось прочитать изображение');
    }
    #-----------------------------------------------------------------------------
    if (!UnLink($File)) {
        return ERROR | @Trigger_Error('[Image_Resize]: не удалось удалить временный файл');
    }
    #-----------------------------------------------------------------------------
    return $Result;
}