function create_histogram($filename) { $img = imagecreatefromfile($filename); $size = getimagesize($filename); $width = $size[0]; $height = $size[1]; $thumbnail_gd_image = imagecreatetruecolor(100, 100); imagecopyresampled($thumbnail_gd_image, $img, 0, 0, 0, 0, 100, 100, $width, $height); $img = $thumbnail_gd_image; $histogram = array(); for ($x = 0; $x < 100; $x++) { for ($y = 0; $y < 100; $y++) { $rgb = imagecolorat($img, $x, $y); $colors = imagecolorsforindex($img, $rgb); $r = str_pad(dechex($colors['red']), 2, "0", STR_PAD_LEFT); $g = str_pad(dechex($colors['green']), 2, "0", STR_PAD_LEFT); $b = str_pad(dechex($colors['blue']), 2, "0", STR_PAD_LEFT); $hex_color = $r . $g . $b . ''; if (!array_key_exists($hex_color, $histogram)) { $histogram[$hex_color] = 0; } $histogram[$hex_color]++; } } return $histogram; }
public function __construct($settings) { $this->settings = $settings; $this->source = $this->settings->path . urldecode($this->settings->file); $this->image = imagecreatefromfile($this->source); $this->mime = getimagesize($this->source); }
public function apply($resource) { // Find original dimensions: $imageWidth = imagesx($resource->image); $imageHeight = imagesy($resource->image); $image = imagecreatefromfile($this->settings->file); imagesavealpha($image, true); imagesavealpha($resource->image, true); $width = imagesx($image); $height = imagesy($image); $margin = $this->settings->margin; // Calculate X alignment: if ($this->settings->xalign == 'left') { $offsetX = $margin; } else { if ($this->settings->xalign == 'right') { $offsetX = round(max($imageWidth, $width) - min($imageWidth, $width)) - $margin; } else { $xalign = 2; if (is_numeric($this->settings->yalign)) { $xalign = (int) $this->settings->yalign / 25; } $offsetX = 0 - round((min($imageWidth, $width) - max($imageWidth, $width)) / $xalign); } } // Calculate Y alignment: if ($this->settings->yalign == 'top') { $offsetY = $margin; } else { if ($this->settings->yalign == 'bottom') { $offsetY = round(max($imageHeight, $height) - min($imageHeight, $height)) - $margin; } else { $yalign = 2; if (is_numeric($this->settings->yalign)) { $yalign = (int) $this->settings->yalign / 25; } $offsetY = 0 - round((min($imageHeight, $height) - max($imageHeight, $height)) / $yalign); } } imagecopyresampled($resource->image, $image, $offsetX, $offsetY, 0, 0, $width, $height, $width, $height); }
public function preRender() { $realiconfile = $this->node->owner->ProcessString($this->iconfile, $this); if (is_readable($realiconfile)) { // TODO - this should be in Draw(), not here. // imagealphablending($im, true); // draw the supplied icon, instead of the labelled box $iconImageRef = imagecreatefromfile($realiconfile); if (true === isset($this->iconFillColour)) { $this->colourizeImage($iconImageRef, $this->iconFillColour); } if ($iconImageRef) { $icon_w = imagesx($iconImageRef); $icon_h = imagesy($iconImageRef); if ($this->iconscalew * $this->iconscaleh > 0) { wm_debug("If this is the last thing in your logs, you probably have a buggy GD library. Get > 2.0.33 or use PHP builtin.\n"); imagealphablending($iconImageRef, true); wm_debug("SCALING ICON here\n"); if ($icon_w > $icon_h) { $scalefactor = $icon_w / $this->iconscalew; } else { $scalefactor = $icon_h / $this->iconscaleh; } $new_width = $icon_w / $scalefactor; $new_height = $icon_h / $scalefactor; $scaled = imagecreatetruecolor($new_width, $new_height); imagealphablending($scaled, false); imagecopyresampled($scaled, $iconImageRef, 0, 0, 0, 0, $new_width, $new_height, $icon_w, $icon_h); imagedestroy($iconImageRef); $iconImageRef = $scaled; } } else { wm_warn("Couldn't open ICON: '" . $realiconfile . "' - is it a PNG, JPEG or GIF? [WMWARN37]\n"); } } else { if ($realiconfile != 'none') { wm_warn("ICON '" . $realiconfile . "' does not exist, or is not readable. Check path and permissions. [WMARN38]\n"); } } }
function cropImage($w, $h, $nw, $nh, $source) { $simg = imagecreatefromfile($source); $dimg = imagecreatetruecolor($nw, $nh); $wm = $w / $nw; $hm = $h / $nh; $h_height = $nh / 2; $w_height = $nw / 2; if ($w > $h) { $adjusted_width = $w / $hm; $half_width = $adjusted_width / 2; $int_width = $half_width - $w_height; imagecopyresampled($dimg, $simg, -$int_width, 0, 0, 0, $adjusted_width, $nh, $w, $h); } elseif ($w < $h || $w == $h) { $adjusted_height = $h / $wm; $half_height = $adjusted_height / 2; $int_height = $half_height - $h_height; imagecopyresampled($dimg, $simg, 0, -$int_height, 0, 0, $nw, $adjusted_height, $w, $h); } else { imagecopyresampled($dimg, $simg, 0, 0, 0, 0, $nw, $nh, $w, $h); } imagejpeg($dimg, $source, 100); }
break; case IMAGETYPE_PNG: return imagecreatefrompng($image_path); break; default: return ''; break; } } // load source image to memory $image = imagecreatefromfile($_GET['image']); if (!$image) { die('Unable to open image'); } // load watermark to memory $watermark = imagecreatefromfile($_GET['watermark']); if (!$image) { die('Unable to open watermark'); } // calculate the position of the watermark in the output image (the // watermark shall be placed in the lower right corner) $watermark_pos_x = imagesx($image) - imagesx($watermark) - 8; $watermark_pos_y = imagesy($image) - imagesy($watermark) - 10; // merge the source image and the watermark imagecopy($image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, imagesx($watermark), imagesy($watermark)); // output watermarked image to browser header('Content-Type: image/jpeg'); imagejpeg($image, '', 100); // use best image quality (100) // remove the images from memory imagedestroy($image);
function pre_render($im, &$map) { // don't bother drawing if there's no position - it's a template if (is_null($this->x)) { return; } if (is_null($this->y)) { return; } // apparently, some versions of the gd extension will crash // if we continue... if ($this->label == '' && $this->iconfile == '') { return; } // start these off with sensible values, so that bbox // calculations are easier. $icon_x1 = $this->x; $icon_x2 = $this->x; $icon_y1 = $this->y; $icon_y2 = $this->y; $label_x1 = $this->x; $label_x2 = $this->x; $label_y1 = $this->y; $label_y2 = $this->y; $boxwidth = 0; $boxheight = 0; $icon_w = 0; $icon_h = 0; $col = new Colour(-1, -1, -1); # print $col->as_string(); // if a target is specified, and you haven't forced no background, then the background will // come from the SCALE in USESCALE if (!empty($this->targets) && $this->usescale != 'none') { $pc = 0; if ($this->scalevar == 'in') { $pc = $this->inpercent; $col = $this->colours[IN]; } if ($this->scalevar == 'out') { $pc = $this->outpercent; $col = $this->colours[OUT]; } } elseif ($this->labelbgcolour != array(-1, -1, -1)) { // $col=myimagecolorallocate($node_im, $this->labelbgcolour[0], $this->labelbgcolour[1], $this->labelbgcolour[2]); $col = new Colour($this->labelbgcolour); } $colicon = null; if (!empty($this->targets) && $this->useiconscale != 'none') { wm_debug("Colorising the icon\n"); $pc = 0; $val = 0; if ($this->iconscalevar == 'in') { $pc = $this->inpercent; $col = $this->colours[IN]; $val = $this->bandwidth_in; } if ($this->iconscalevar == 'out') { $pc = $this->outpercent; $col = $this->colours[OUT]; $val = $this->bandwidth_out; } if ($this->iconscaletype == 'percent') { list($colicon, $node_iconscalekey, $icontag) = $map->NewColourFromPercent($pc, $this->useiconscale, $this->name); } else { // use the absolute value if we aren't doing percentage scales. list($colicon, $node_iconscalekey, $icontag) = $map->NewColourFromPercent($val, $this->useiconscale, $this->name, FALSE); } } // figure out a bounding rectangle for the label if ($this->label != '') { $padding = 4.0; $padfactor = 1.0; $this->proclabel = $map->ProcessString($this->label, $this, TRUE, TRUE); // if screenshot_mode is enabled, wipe any letters to X and wipe any IP address to 127.0.0.1 // hopefully that will preserve enough information to show cool stuff without leaking info if ($map->get_hint('screenshot_mode') == 1) { $this->proclabel = screenshotify($this->proclabel); } list($strwidth, $strheight) = $map->myimagestringsize($this->labelfont, $this->proclabel); if ($this->labelangle == 90 || $this->labelangle == 270) { $boxwidth = $strheight * $padfactor + $padding; $boxheight = $strwidth * $padfactor + $padding; wm_debug("Node->pre_render: " . $this->name . " Label Metrics are: {$strwidth} x {$strheight} -> {$boxwidth} x {$boxheight}\n"); $label_x1 = $this->x - $boxwidth / 2; $label_y1 = $this->y - $boxheight / 2; $label_x2 = $this->x + $boxwidth / 2; $label_y2 = $this->y + $boxheight / 2; if ($this->labelangle == 90) { $txt_x = $this->x + $strheight / 2; $txt_y = $this->y + $strwidth / 2; } if ($this->labelangle == 270) { $txt_x = $this->x - $strheight / 2; $txt_y = $this->y - $strwidth / 2; } } if ($this->labelangle == 0 || $this->labelangle == 180) { $boxwidth = $strwidth * $padfactor + $padding; $boxheight = $strheight * $padfactor + $padding; wm_debug("Node->pre_render: " . $this->name . " Label Metrics are: {$strwidth} x {$strheight} -> {$boxwidth} x {$boxheight}\n"); $label_x1 = $this->x - $boxwidth / 2; $label_y1 = $this->y - $boxheight / 2; $label_x2 = $this->x + $boxwidth / 2; $label_y2 = $this->y + $boxheight / 2; $txt_x = $this->x - $strwidth / 2; $txt_y = $this->y + $strheight / 2; if ($this->labelangle == 180) { $txt_x = $this->x + $strwidth / 2; $txt_y = $this->y - $strheight / 2; } # $this->width = $boxwidth; # $this->height = $boxheight; } $map->nodes[$this->name]->width = $boxwidth; $map->nodes[$this->name]->height = $boxheight; # print "TEXT at $txt_x , $txt_y\n"; } // figure out a bounding rectangle for the icon if ($this->iconfile != '') { $icon_im = NULL; $icon_w = 0; $icon_h = 0; if ($this->iconfile == 'rbox' || $this->iconfile == 'box' || $this->iconfile == 'round' || $this->iconfile == 'inpie' || $this->iconfile == 'outpie' || $this->iconfile == 'gauge' || $this->iconfile == 'nink') { wm_debug("Artificial Icon type " . $this->iconfile . " for {$this->name}\n"); // this is an artificial icon - we don't load a file for it $icon_im = imagecreatetruecolor($this->iconscalew, $this->iconscaleh); imageSaveAlpha($icon_im, TRUE); $nothing = imagecolorallocatealpha($icon_im, 128, 0, 0, 127); imagefill($icon_im, 0, 0, $nothing); $fill = NULL; $ink = NULL; $aifill = new Colour($this->aiconfillcolour); $aiink = new Colour($this->aiconoutlinecolour); if ($aifill->is_copy() && !$col->is_none()) { $fill = $col; } else { if ($aifill->is_real()) { $fill = $aifill; } } if ($this->aiconoutlinecolour != array(-1, -1, -1)) { $ink = $aiink; } if ($this->iconfile == 'box') { if ($fill !== NULL && !$fill->is_none()) { imagefilledrectangle($icon_im, 0, 0, $this->iconscalew - 1, $this->iconscaleh - 1, $fill->gdallocate($icon_im)); } if ($ink !== NULL && !$ink->is_none()) { imagerectangle($icon_im, 0, 0, $this->iconscalew - 1, $this->iconscaleh - 1, $ink->gdallocate($icon_im)); } } if ($this->iconfile == 'rbox') { if ($fill !== NULL && !$fill->is_none()) { imagefilledroundedrectangle($icon_im, 0, 0, $this->iconscalew - 1, $this->iconscaleh - 1, 4, $fill->gdallocate($icon_im)); } if ($ink !== NULL && !$ink->is_none()) { imageroundedrectangle($icon_im, 0, 0, $this->iconscalew - 1, $this->iconscaleh - 1, 4, $ink->gdallocate($icon_im)); } } if ($this->iconfile == 'round') { $rx = $this->iconscalew / 2 - 1; $ry = $this->iconscaleh / 2 - 1; if ($fill !== NULL && !$fill->is_none()) { imagefilledellipse($icon_im, $rx, $ry, $rx * 2, $ry * 2, $fill->gdallocate($icon_im)); } if ($ink !== NULL && !$ink->is_none()) { imageellipse($icon_im, $rx, $ry, $rx * 2, $ry * 2, $ink->gdallocate($icon_im)); } } if ($this->iconfile == 'nink') { // print "NINK **************************************************************\n"; $rx = $this->iconscalew / 2 - 1; $ry = $this->iconscaleh / 2 - 1; $size = $this->iconscalew; $quarter = $size / 4; $col1 = $this->colours[OUT]; $col2 = $this->colours[IN]; assert('!is_null($col1)'); assert('!is_null($col2)'); imagefilledarc($icon_im, $rx - 1, $ry, $size, $size, 270, 90, $col1->gdallocate($icon_im), IMG_ARC_PIE); imagefilledarc($icon_im, $rx + 1, $ry, $size, $size, 90, 270, $col2->gdallocate($icon_im), IMG_ARC_PIE); imagefilledarc($icon_im, $rx - 1, $ry + $quarter, $quarter * 2, $quarter * 2, 0, 360, $col1->gdallocate($icon_im), IMG_ARC_PIE); imagefilledarc($icon_im, $rx + 1, $ry - $quarter, $quarter * 2, $quarter * 2, 0, 360, $col2->gdallocate($icon_im), IMG_ARC_PIE); if ($ink !== NULL && !$ink->is_none()) { // XXX - need a font definition from somewhere for NINK text $font = 1; $instr = $map->ProcessString("{node:this:bandwidth_in:%.1k}", $this); $outstr = $map->ProcessString("{node:this:bandwidth_out:%.1k}", $this); list($twid, $thgt) = $map->myimagestringsize($font, $instr); $map->myimagestring($icon_im, $font, $rx - $twid / 2, $ry - $quarter + $thgt / 2, $instr, $ink->gdallocate($icon_im)); list($twid, $thgt) = $map->myimagestringsize($font, $outstr); $map->myimagestring($icon_im, $font, $rx - $twid / 2, $ry + $quarter + $thgt / 2, $outstr, $ink->gdallocate($icon_im)); imageellipse($icon_im, $rx, $ry, $rx * 2, $ry * 2, $ink->gdallocate($icon_im)); // imagearc($icon_im, $rx,$ry,$quarter*4,$quarter*4, 0,360, $ink->gdallocate($icon_im)); } // print "NINK ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"; } // XXX - needs proper colours if ($this->iconfile == 'inpie' || $this->iconfile == 'outpie') { # list($colpie,$node_iconscalekey,$icontag) = $map->NewColourFromPercent($pc, $this->useiconscale,$this->name); if ($this->iconfile == 'inpie') { $segment_angle = $this->inpercent / 100 * 360; } if ($this->iconfile == 'outpie') { $segment_angle = $this->outpercent / 100 * 360; } $rx = $this->iconscalew / 2 - 1; $ry = $this->iconscaleh / 2 - 1; if ($fill !== NULL && !$fill->is_none()) { imagefilledellipse($icon_im, $rx, $ry, $rx * 2, $ry * 2, $fill->gdallocate($icon_im)); } if ($ink !== NULL && !$ink->is_none()) { // imagefilledarc ( resource $image , int $cx , int $cy , int $width , int $height , int $start , int $end , int $color , int $style ) imagefilledarc($icon_im, $rx, $ry, $rx * 2, $ry * 2, 0, $segment_angle, $ink->gdallocate($icon_im), IMG_ARC_PIE); } if ($fill !== NULL && !$fill->is_none()) { imageellipse($icon_im, $rx, $ry, $rx * 2, $ry * 2, $fill->gdallocate($icon_im)); } // warn('inpie AICON not implemented yet [WMWARN99]'); } // if($this->iconfile=='outpie') { warn('outpie AICON not implemented yet [WMWARN99]'); } if ($this->iconfile == 'gauge') { wm_warn('gauge AICON not implemented yet [WMWARN99]'); } } else { $this->iconfile = $map->ProcessString($this->iconfile, $this); if (is_readable($this->iconfile)) { imagealphablending($im, true); // draw the supplied icon, instead of the labelled box $icon_im = imagecreatefromfile($this->iconfile); # $icon_im = imagecreatefrompng($this->iconfile); if (function_exists("imagefilter") && isset($colicon) && $this->get_hint("use_imagefilter") == 1) { imagefilter($icon_im, IMG_FILTER_COLORIZE, $colicon->r, $colicon->g, $colicon->b); } else { if (isset($colicon)) { // debug("Skipping unavailable imagefilter() call.\n"); imagecolorize($icon_im, $colicon->r, $colicon->g, $colicon->b); } } wm_debug("If this is the last thing in your logs, you probably have a buggy GD library. Get > 2.0.33 or use PHP builtin.\n"); if ($icon_im) { $icon_w = imagesx($icon_im); $icon_h = imagesy($icon_im); if ($this->iconscalew * $this->iconscaleh > 0) { imagealphablending($icon_im, true); wm_debug("SCALING ICON here\n"); if ($icon_w > $icon_h) { $scalefactor = $icon_w / $this->iconscalew; } else { $scalefactor = $icon_h / $this->iconscaleh; } $new_width = $icon_w / $scalefactor; $new_height = $icon_h / $scalefactor; $scaled = imagecreatetruecolor($new_width, $new_height); imagealphablending($scaled, false); imagecopyresampled($scaled, $icon_im, 0, 0, 0, 0, $new_width, $new_height, $icon_w, $icon_h); imagedestroy($icon_im); $icon_im = $scaled; } } else { wm_warn("Couldn't open ICON: '" . $this->iconfile . "' - is it a PNG, JPEG or GIF? [WMWARN37]\n"); } } else { if ($this->iconfile != 'none') { wm_warn("ICON '" . $this->iconfile . "' does not exist, or is not readable. Check path and permissions. [WMARN38]\n"); } } } if ($icon_im) { $icon_w = imagesx($icon_im); $icon_h = imagesy($icon_im); $icon_x1 = $this->x - $icon_w / 2; $icon_y1 = $this->y - $icon_h / 2; $icon_x2 = $this->x + $icon_w / 2; $icon_y2 = $this->y + $icon_h / 2; $map->nodes[$this->name]->width = imagesx($icon_im); $map->nodes[$this->name]->height = imagesy($icon_im); // $map->imap->addArea("Rectangle", "NODE:" . $this->name . ':0', '', array($icon_x1, $icon_y1, $icon_x2, $icon_y2)); $map->nodes[$this->name]->boundingboxes[] = array($icon_x1, $icon_y1, $icon_x2, $icon_y2); } } // do any offset calculations $dx = 0; $dy = 0; if ($this->labeloffset != '' && $this->iconfile != '') { $this->labeloffsetx = 0; $this->labeloffsety = 0; list($dx, $dy) = calc_offset($this->labeloffset, $icon_w + $boxwidth - 1, $icon_h + $boxheight); #$this->labeloffsetx = $dx; #$this->labeloffsety = $dy; } $label_x1 += $this->labeloffsetx + $dx; $label_x2 += $this->labeloffsetx + $dx; $label_y1 += $this->labeloffsety + $dy; $label_y2 += $this->labeloffsety + $dy; if ($this->label != '') { // $map->imap->addArea("Rectangle", "NODE:" . $this->name .':1', '', array($label_x1, $label_y1, $label_x2, $label_y2)); $map->nodes[$this->name]->boundingboxes[] = array($label_x1, $label_y1, $label_x2, $label_y2); } // work out the bounding box of the whole thing $bbox_x1 = min($label_x1, $icon_x1); $bbox_x2 = max($label_x2, $icon_x2) + 1; $bbox_y1 = min($label_y1, $icon_y1); $bbox_y2 = max($label_y2, $icon_y2) + 1; # imagerectangle($im,$bbox_x1,$bbox_y1,$bbox_x2,$bbox_y2,$map->selected); # imagerectangle($im,$label_x1,$label_y1,$label_x2,$label_y2,$map->black); # imagerectangle($im,$icon_x1,$icon_y1,$icon_x2,$icon_y2,$map->black); // create TWO imagemap entries - one for the label and one for the icon // (so we can have close-spaced icons better) $temp_width = $bbox_x2 - $bbox_x1; $temp_height = $bbox_y2 - $bbox_y1; // create an image of that size and draw into it $node_im = imagecreatetruecolor($temp_width, $temp_height); // ImageAlphaBlending($node_im, FALSE); imageSaveAlpha($node_im, TRUE); $nothing = imagecolorallocatealpha($node_im, 128, 0, 0, 127); imagefill($node_im, 0, 0, $nothing); #$col = $col->gdallocate($node_im); // imagefilledrectangle($node_im,0,0,$temp_width,$temp_height, $nothing); $label_x1 -= $bbox_x1; $label_x2 -= $bbox_x1; $label_y1 -= $bbox_y1; $label_y2 -= $bbox_y1; $icon_x1 -= $bbox_x1; $icon_x2 -= $bbox_x1; $icon_y1 -= $bbox_y1; $icon_y2 -= $bbox_y1; // Draw the icon, if any if (isset($icon_im)) { imagecopy($node_im, $icon_im, $icon_x1, $icon_y1, 0, 0, imagesx($icon_im), imagesy($icon_im)); imagedestroy($icon_im); } // Draw the label, if any if ($this->label != '') { $txt_x -= $bbox_x1; $txt_x += $this->labeloffsetx + $dx; $txt_y -= $bbox_y1; $txt_y += $this->labeloffsety + $dy; # print "FINAL TEXT at $txt_x , $txt_y\n"; // if there's an icon, then you can choose to have no background if (!$col->is_none()) { imagefilledrectangle($node_im, $label_x1, $label_y1, $label_x2, $label_y2, $col->gdallocate($node_im)); } if ($this->selected) { imagerectangle($node_im, $label_x1, $label_y1, $label_x2, $label_y2, $map->selected); // would be nice if it was thicker, too... wimagerectangle($node_im, $label_x1 + 1, $label_y1 + 1, $label_x2 - 1, $label_y2 - 1, $map->selected); } else { $olcol = new Colour($this->labeloutlinecolour); if ($olcol->is_real()) { imagerectangle($node_im, $label_x1, $label_y1, $label_x2, $label_y2, $olcol->gdallocate($node_im)); } } #} $shcol = new Colour($this->labelfontshadowcolour); if ($shcol->is_real()) { $map->myimagestring($node_im, $this->labelfont, $txt_x + 1, $txt_y + 1, $this->proclabel, $shcol->gdallocate($node_im), $this->labelangle); } $txcol = new Colour($this->labelfontcolour[0], $this->labelfontcolour[1], $this->labelfontcolour[2]); #$col=myimagecolorallocate($node_im, $this->labelfontcolour[0], $this->labelfontcolour[1], # $this->labelfontcolour[2]); if ($txcol->is_contrast()) { if ($col->is_real()) { $txcol = $col->contrast(); } else { wm_warn("You can't make a contrast with 'none'. [WMWARN43]\n"); $txcol = new Colour(0, 0, 0); } } $map->myimagestring($node_im, $this->labelfont, $txt_x, $txt_y, $this->proclabel, $txcol->gdallocate($node_im), $this->labelangle); //$map->myimagestring($node_im, $this->labelfont, $txt_x, $txt_y, $this->proclabel, $txcol->gdallocate($node_im),90); } # imagerectangle($node_im,$label_x1,$label_y1,$label_x2,$label_y2,$map->black); # imagerectangle($node_im,$icon_x1,$icon_y1,$icon_x2,$icon_y2,$map->black); $map->nodes[$this->name]->centre_x = $this->x - $bbox_x1; $map->nodes[$this->name]->centre_y = $this->y - $bbox_y1; if (1 == 0) { imageellipse($node_im, $this->centre_x, $this->centre_y, 8, 8, $map->selected); foreach (array("N", "S", "E", "W", "NE", "NW", "SE", "SW") as $corner) { list($dx, $dy) = calc_offset($corner, $this->width, $this->height); imageellipse($node_im, $this->centre_x + $dx, $this->centre_y + $dy, 5, 5, $map->selected); } } # $this->image = $node_im; $map->nodes[$this->name]->image = $node_im; }
function DrawMap($filename = '', $thumbnailfile = '', $thumbnailmax = 250, $withnodes = TRUE, $use_via_overlay = FALSE, $use_rel_overlay=FALSE) { wm_debug("Trace: DrawMap()\n"); metadump("# start",true); $bgimage=NULL; if($this->configfile != "") { $this->cachefile_version = crc32(file_get_contents($this->configfile)); } else { $this->cachefile_version = crc32("........"); } wm_debug("Running Post-Processing Plugins...\n"); foreach ($this->postprocessclasses as $post_class) { wm_debug("Running $post_class"."->run()\n"); //call_user_func_array(array($post_class, 'run'), array(&$this)); $this->plugins['post'][$post_class]->run($this); } wm_debug("Finished Post-Processing Plugins...\n"); wm_debug("=====================================\n"); wm_debug("Start of Map Drawing\n"); $this->datestamp = strftime($this->stamptext, time()); // do the basic prep work if ($this->background != '') { if (is_readable($this->background)) { $bgimage=imagecreatefromfile($this->background); if (!$bgimage) { wm_warn ("Failed to open background image. One possible reason: Is your BACKGROUND really a PNG?\n"); } else { $this->width=imagesx($bgimage); $this->height=imagesy($bgimage); } } else { wm_warn ("Your background image file could not be read. Check the filename, and permissions, for " . $this->background . "\n"); } } $image=wimagecreatetruecolor($this->width, $this->height); # $image = imagecreate($this->width, $this->height); if (!$image) { wm_warn ("Couldn't create output image in memory (" . $this->width . "x" . $this->height . ")."); } else { ImageAlphaBlending($image, true); # imageantialias($image,true); // by here, we should have a valid image handle // save this away, now $this->image=$image; $this->white=myimagecolorallocate($image, 255, 255, 255); $this->black=myimagecolorallocate($image, 0, 0, 0); $this->grey=myimagecolorallocate($image, 192, 192, 192); $this->selected=myimagecolorallocate($image, 255, 0, 0); // for selections in the editor $this->AllocateScaleColours($image); // fill with background colour anyway, in case the background image failed to load wimagefilledrectangle($image, 0, 0, $this->width, $this->height, $this->colours['DEFAULT']['BG']['gdref1']); if ($bgimage) { imagecopy($image, $bgimage, 0, 0, 0, 0, $this->width, $this->height); imagedestroy ($bgimage); } // Now it's time to draw a map // do the node rendering stuff first, regardless of where they are actually drawn. // this is so we can get the size of the nodes, which links will need if they use offsets foreach ($this->nodes as $node) { // don't try and draw template nodes wm_debug("Pre-rendering ".$node->name." to get bounding boxes.\n"); if(!is_null($node->x)) $this->nodes[$node->name]->pre_render($image, $this); } $all_layers = array_keys($this->seen_zlayers); sort($all_layers); foreach ($all_layers as $z) { $z_items = $this->seen_zlayers[$z]; wm_debug("Drawing layer $z\n"); // all the map 'furniture' is fixed at z=1000 if($z==1000) { foreach ($this->colours as $scalename=>$colours) { wm_debug("Drawing KEY for $scalename if necessary.\n"); if( (isset($this->numscales[$scalename])) && (isset($this->keyx[$scalename])) && ($this->keyx[$scalename] >= 0) && ($this->keyy[$scalename] >= 0) ) { if($this->keystyle[$scalename]=='classic') $this->DrawLegend_Classic($image,$scalename,FALSE); if($this->keystyle[$scalename]=='horizontal') $this->DrawLegend_Horizontal($image,$scalename,$this->keysize[$scalename]); if($this->keystyle[$scalename]=='vertical') $this->DrawLegend_Vertical($image,$scalename,$this->keysize[$scalename]); if($this->keystyle[$scalename]=='inverted') $this->DrawLegend_Vertical($image,$scalename,$this->keysize[$scalename],true); if($this->keystyle[$scalename]=='tags') $this->DrawLegend_Classic($image,$scalename,TRUE); } } $this->DrawTimestamp($image, $this->timefont, $this->colours['DEFAULT']['TIME']['gdref1']); if(! is_null($this->min_data_time)) { $this->DrawTimestamp($image, $this->timefont, $this->colours['DEFAULT']['TIME']['gdref1'],"MIN"); $this->DrawTimestamp($image, $this->timefont, $this->colours['DEFAULT']['TIME']['gdref1'],"MAX"); } $this->DrawTitle($image, $this->titlefont, $this->colours['DEFAULT']['TITLE']['gdref1']); } if(is_array($z_items)) { foreach($z_items as $it) { if(strtolower(get_class($it))=='weathermaplink') { // only draw LINKs if they have NODES defined (not templates) // (also, check if the link still exists - if this is in the editor, it may have been deleted by now) if ( isset($this->links[$it->name]) && isset($it->a) && isset($it->b)) { wm_debug("Drawing LINK ".$it->name."\n"); $this->links[$it->name]->Draw($image, $this); } } if(strtolower(get_class($it))=='weathermapnode') { // if(!is_null($it->x)) $it->pre_render($image, $this); if($withnodes) { // don't try and draw template nodes if( isset($this->nodes[$it->name]) && !is_null($it->x)) { # print "::".get_class($it)."\n"; wm_debug("Drawing NODE ".$it->name."\n"); $this->nodes[$it->name]->NewDraw($image, $this); $ii=0; foreach($this->nodes[$it->name]->boundingboxes as $bbox) { # $areaname = "NODE:" . $it->name . ':'.$ii; $areaname = "NODE:N". $it->id . ":" . $ii; $this->imap->addArea("Rectangle", $areaname, '', $bbox); wm_debug("Adding imagemap area"); $ii++; } wm_debug("Added $ii bounding boxes too\n"); } } } } } } $overlay = myimagecolorallocate($image, 200, 0, 0); // for the editor, we can optionally overlay some other stuff if($this->context == 'editor') { if($use_rel_overlay) { # $overlay = myimagecolorallocate($image, 200, 0, 0); // first, we can show relatively positioned NODEs foreach ($this->nodes as $node) { if($node->relative_to != '') { $rel_x = $this->nodes[$node->relative_to]->x; $rel_y = $this->nodes[$node->relative_to]->y; imagearc($image,$node->x, $node->y, 15,15,0,360,$overlay); imagearc($image,$node->x, $node->y, 16,16,0,360,$overlay); imageline($image,$node->x, $node->y, $rel_x, $rel_y, $overlay); } } } if($use_via_overlay) { // then overlay VIAs, so they can be seen foreach($this->links as $link) { foreach ($link->vialist as $via) { if(isset($via[2])) { $x = $this->nodes[$via[2]]->x + $via[0]; $y = $this->nodes[$via[2]]->y + $via[1]; } else { $x = $via[0]; $y = $via[1]; } imagearc($image, $x,$y, 10,10,0,360,$overlay); imagearc($image, $x,$y, 12,12,0,360,$overlay); } } } } #$this->myimagestring($image, 3, 200, 100, "Test 1\nLine 2", $overlay,0); # $this->myimagestring($image, 30, 100, 100, "Test 1\nLine 2", $overlay,0); #$this->myimagestring($image, 30, 200, 200, "Test 1\nLine 2", $overlay,45); // Ready to output the results... if($filename == 'null') { // do nothing at all - we just wanted the HTML AREAs for the editor or HTML output } else { if ($filename == '') { imagepng ($image); } else { $result = FALSE; $functions = TRUE; if(function_exists('imagejpeg') && preg_match("/\.jpg/i",$filename)) { wm_debug("Writing JPEG file to $filename\n"); $result = imagejpeg($image, $filename); } elseif(function_exists('imagegif') && preg_match("/\.gif/i",$filename)) { wm_debug("Writing GIF file to $filename\n"); $result = imagegif($image, $filename); } elseif(function_exists('imagepng') && preg_match("/\.png/i",$filename)) { wm_debug("Writing PNG file to $filename\n"); $result = imagepng($image, $filename); } else { wm_warn("Failed to write map image. No function existed for the image format you requested. [WMWARN12]\n"); $functions = FALSE; } if(($result==FALSE) && ($functions==TRUE)) { if(file_exists($filename)) { wm_warn("Failed to overwrite existing image file $filename - permissions of existing file are wrong? [WMWARN13]"); } else { wm_warn("Failed to create image file $filename - permissions of output directory are wrong? [WMWARN14]"); } } } } if($this->context == 'editor2') { $cachefile = $this->cachefolder.DIRECTORY_SEPARATOR.dechex(crc32($this->configfile))."_bg.".$this->cachefile_version.".png"; imagepng($image, $cachefile); $cacheuri = $this->cachefolder.'/'.dechex(crc32($this->configfile))."_bg.".$this->cachefile_version.".png"; $this->mapcache = $cacheuri; } if (function_exists('imagecopyresampled')) { // if one is specified, and we can, write a thumbnail too if ($thumbnailfile != '') { $result = FALSE; if ($this->width > $this->height) { $factor=($thumbnailmax / $this->width); } else { $factor=($thumbnailmax / $this->height); } $this->thumb_width = $this->width * $factor; $this->thumb_height = $this->height * $factor; $imagethumb=imagecreatetruecolor($this->thumb_width, $this->thumb_height); imagecopyresampled($imagethumb, $image, 0, 0, 0, 0, $this->thumb_width, $this->thumb_height, $this->width, $this->height); $result = imagepng($imagethumb, $thumbnailfile); imagedestroy($imagethumb); if(($result==FALSE)) { if(file_exists($filename)) { wm_warn("Failed to overwrite existing image file $filename - permissions of existing file are wrong? [WMWARN15]"); } else { wm_warn("Failed to create image file $filename - permissions of output directory are wrong? [WMWARN16]"); } } } } else { wm_warn("Skipping thumbnail creation, since we don't have the necessary function. [WMWARN17]"); } imagedestroy ($image); } }
} } if ($watermark_onoff) { //--- transparante watermark if ($watermark_file == 'watermark.png') { $watermark_file = $config['root_path'] . '/modules/Showtime/images/watermark.png'; } else { $watermark_file = $config['image_uploads_path'] . '/' . $watermark_file; } if (file_exists($watermark_file)) { $watermark = imagecreatefromfile($watermark_file); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); imagecreatetruecolor($watermark_width, $watermark_height); //--- orriginele image $image = imagecreatefromfile($fullpath); $size = getimagesize($fullpath); //--- Calculate position $padding_x = $watermark_padding_x; $padding_y = $watermark_padding_y; switch ($watermark_pos) { //bottom_right bottom_left top_right top_left case "bottom_right": $xas = $size[0] - $watermark_width - $padding_x; $yas = $size[1] - $watermark_height - $padding_y; break; case "bottom_left": $xas = $padding_x; $yas = $size[1] - $watermark_height - $padding_y; break; case "top_right":
function preRender($im, &$map) { // don't bother drawing if it's a template if ($this->isTemplate()) { return; } // apparently, some versions of the gd extension will crash if we continue... if ($this->label == '' && $this->iconfile == '') { return; } // start these off with sensible values, so that bbox // calculations are easier. $labelBoundingBox = new WMBoundingBox(); $labelBoundingBox->addWMPoint($this->getPosition()); $iconBoundingBox = new WMBoundingBox(); $iconBoundingBox->addWMPoint($this->getPosition()); $icon_x1 = $this->x; $icon_x2 = $this->x; $icon_y1 = $this->y; $icon_y2 = $this->y; $label_x1 = $this->x; $label_x2 = $this->x; $label_y1 = $this->y; $label_y2 = $this->y; $boxWidth = 0; $boxHeight = 0; $icon_w = 0; $icon_h = 0; list($labelFillColour, $iconFillColour) = $this->calculateColours($map); // figure out a bounding rectangle for the label if ($this->label != '') { $padding = 4.0; $padFactor = 1.0; $this->processedLabel = $map->ProcessString($this->label, $this, true, true); // if screenshot_mode is enabled, wipe any letters to X and wipe any IP address to 127.0.0.1 // hopefully that will preserve enough information to show cool stuff without leaking info if ($map->get_hint('screenshot_mode') == 1) { $this->processedLabel = WMUtility::stringAnonymise($this->processedLabel); } list($stringWidth, $stringHeight) = $map->myimagestringsize($this->labelfont, $this->processedLabel); if ($this->labelangle == 90 || $this->labelangle == 270) { $boxWidth = $stringHeight * $padFactor + $padding; $boxHeight = $stringWidth * $padFactor + $padding; } else { $boxWidth = $stringWidth * $padFactor + $padding; $boxHeight = $stringHeight * $padFactor + $padding; } $halfWidth = $boxWidth / 2; $halfHeight = $boxHeight / 2; $label_x1 = $this->x - $halfWidth; $label_y1 = $this->y - $halfHeight; $label_x2 = $this->x + $halfWidth; $label_y2 = $this->y + $halfHeight; $labelBoundingBox->addPoint($this->x - $halfWidth, $this->y - $halfHeight); $labelBoundingBox->addPoint($this->x + $halfWidth, $this->y + $halfHeight); wm_debug("Node->pre_render: " . $this->name . " Label Metrics are: {$stringWidth} x {$stringHeight} -> {$boxWidth} x {$boxHeight}\n"); if ($this->labelangle == 90) { $txt_x = $this->x + $stringHeight / 2; $txt_y = $this->y + $stringWidth / 2; } if ($this->labelangle == 270) { $txt_x = $this->x - $stringHeight / 2; $txt_y = $this->y - $stringWidth / 2; } if ($this->labelangle == 0) { $txt_x = $this->x - $stringWidth / 2; $txt_y = $this->y + $stringHeight / 2; } if ($this->labelangle == 180) { $txt_x = $this->x + $stringWidth / 2; $txt_y = $this->y - $stringHeight / 2; } $this->width = $boxWidth; $this->height = $boxHeight; } // figure out a bounding rectangle for the icon if ($this->iconfile != '') { $iconImageRef = null; $icon_w = 0; $icon_h = 0; if ($this->iconfile == 'rbox' || $this->iconfile == 'box' || $this->iconfile == 'round' || $this->iconfile == 'inpie' || $this->iconfile == 'outpie' || $this->iconfile == 'gauge' || $this->iconfile == 'nink') { wm_debug("Artificial Icon type " . $this->iconfile . " for {$this->name}\n"); // this is an artificial icon - we don't load a file for it $iconImageRef = imagecreatetruecolor($this->iconscalew, $this->iconscaleh); imageSaveAlpha($iconImageRef, true); $nothing = imagecolorallocatealpha($iconImageRef, 128, 0, 0, 127); imagefill($iconImageRef, 0, 0, $nothing); $fill = null; $ink = null; $aiconFillColour = $this->aiconfillcolour; $aiconInkColour = $this->aiconoutlinecolour; // if useiconscale isn't set, then use the static colour defined, or copy the colour from the label if ($this->useiconscale == "none") { if ($aiconFillColour->isCopy() && !$labelFillColour->isNone()) { $fill = $labelFillColour; } else { if ($aiconFillColour->isRealColour()) { $fill = $aiconFillColour; } } } else { // if useiconscale IS defined, use that to figure out the fill colour $fill = $iconFillColour; } if (!$this->aiconoutlinecolour->isNone()) { $ink = $aiconInkColour; } wm_debug("AICON colours are {$ink} and {$fill}\n"); if ($this->iconfile == 'box') { $this->drawAIconBox($iconImageRef, $fill, $ink); } if ($this->iconfile == 'rbox') { $this->drawAIconRoundedBox($iconImageRef, $fill, $ink); } if ($this->iconfile == 'round') { $this->drawAIconRound($iconImageRef, $fill, $ink); } if ($this->iconfile == 'nink') { $this->drawAIconNINK($iconImageRef, $ink); } // XXX - needs proper colours if ($this->iconfile == 'inpie' || $this->iconfile == 'outpie') { $this->drawAIconPie($iconImageRef, $fill, $ink); } if ($this->iconfile == 'gauge') { wm_warn('gauge AICON not implemented yet [WMWARN99]'); } } else { $realiconfile = $map->ProcessString($this->iconfile, $this); if (is_readable($realiconfile)) { imagealphablending($im, true); // draw the supplied icon, instead of the labelled box $iconImageRef = imagecreatefromfile($realiconfile); if (true === isset($iconFillColour)) { $this->colourizeImage($iconImageRef, $iconFillColour); } if ($iconImageRef) { $icon_w = imagesx($iconImageRef); $icon_h = imagesy($iconImageRef); if ($this->iconscalew * $this->iconscaleh > 0) { wm_debug("If this is the last thing in your logs, you probably have a buggy GD library. Get > 2.0.33 or use PHP builtin.\n"); imagealphablending($iconImageRef, true); wm_debug("SCALING ICON here\n"); if ($icon_w > $icon_h) { $scalefactor = $icon_w / $this->iconscalew; } else { $scalefactor = $icon_h / $this->iconscaleh; } $new_width = $icon_w / $scalefactor; $new_height = $icon_h / $scalefactor; $scaled = imagecreatetruecolor($new_width, $new_height); imagealphablending($scaled, false); imagecopyresampled($scaled, $iconImageRef, 0, 0, 0, 0, $new_width, $new_height, $icon_w, $icon_h); imagedestroy($iconImageRef); $iconImageRef = $scaled; } } else { wm_warn("Couldn't open ICON: '" . $realiconfile . "' - is it a PNG, JPEG or GIF? [WMWARN37]\n"); } } else { if ($realiconfile != 'none') { wm_warn("ICON '" . $realiconfile . "' does not exist, or is not readable. Check path and permissions. [WMARN38]\n"); } } } if ($iconImageRef) { $icon_w = imagesx($iconImageRef); $icon_h = imagesy($iconImageRef); $icon_x1 = $this->x - $icon_w / 2; $icon_y1 = $this->y - $icon_h / 2; $icon_x2 = $this->x + $icon_w / 2; $icon_y2 = $this->y + $icon_h / 2; $this->width = imagesx($iconImageRef); $this->height = imagesy($iconImageRef); $this->boundingboxes[] = array($icon_x1, $icon_y1, $icon_x2, $icon_y2); } } // do any offset calculations $deltaX = 0; $deltaY = 0; if ($this->labeloffset != '' && $this->iconfile != '') { $this->labeloffsetx = 0; $this->labeloffsety = 0; list($deltaX, $deltaY) = WMUtility::calculateOffset($this->labeloffset, $icon_w + $boxWidth - 1, $icon_h + $boxHeight); } $label_x1 += $this->labeloffsetx + $deltaX; $label_x2 += $this->labeloffsetx + $deltaX; $label_y1 += $this->labeloffsety + $deltaY; $label_y2 += $this->labeloffsety + $deltaY; if ($this->label != '') { $this->boundingboxes[] = array($label_x1, $label_y1, $label_x2, $label_y2); } // work out the bounding box of the whole thing $bbox_x1 = min($label_x1, $icon_x1); $bbox_x2 = max($label_x2, $icon_x2) + 1; $bbox_y1 = min($label_y1, $icon_y1); $bbox_y2 = max($label_y2, $icon_y2) + 1; // create TWO imagemap entries - one for the label and one for the icon // (so we can have close-spaced icons better) $temp_width = $bbox_x2 - $bbox_x1; $temp_height = $bbox_y2 - $bbox_y1; // create an image of that size and draw into it $node_im = imagecreatetruecolor($temp_width, $temp_height); // ImageAlphaBlending($node_im, false); imageSaveAlpha($node_im, true); $nothing = imagecolorallocatealpha($node_im, 128, 0, 0, 127); imagefill($node_im, 0, 0, $nothing); $label_x1 -= $bbox_x1; $label_x2 -= $bbox_x1; $label_y1 -= $bbox_y1; $label_y2 -= $bbox_y1; $icon_x1 -= $bbox_x1; $icon_y1 -= $bbox_y1; // Draw the icon, if any if (isset($iconImageRef)) { imagecopy($node_im, $iconImageRef, $icon_x1, $icon_y1, 0, 0, imagesx($iconImageRef), imagesy($iconImageRef)); imagedestroy($iconImageRef); } // Draw the label, if any if ($this->label != '') { $txt_x -= $bbox_x1; $txt_x += $this->labeloffsetx + $deltaX; $txt_y -= $bbox_y1; $txt_y += $this->labeloffsety + $deltaY; // if there's an icon, then you can choose to have no background if (!$this->labelbgcolour->isNone()) { imagefilledrectangle($node_im, $label_x1, $label_y1, $label_x2, $label_y2, $labelFillColour->gdAllocate($node_im)); } if ($this->selected) { imagerectangle($node_im, $label_x1, $label_y1, $label_x2, $label_y2, $map->selected); // would be nice if it was thicker, too... imagerectangle($node_im, $label_x1 + 1, $label_y1 + 1, $label_x2 - 1, $label_y2 - 1, $map->selected); } else { // $label_outline_colour = $this->labeloutlinecolour; if ($this->labeloutlinecolour->isRealColour()) { imagerectangle($node_im, $label_x1, $label_y1, $label_x2, $label_y2, $this->labeloutlinecolour->gdallocate($node_im)); } } // $shcol = $this->labelfontshadowcolour; if ($this->labelfontshadowcolour->isRealColour()) { $map->myimagestring($node_im, $this->labelfont, $txt_x + 1, $txt_y + 1, $this->processedLabel, $this->labelfontshadowcolour->gdallocate($node_im), $this->labelangle); } $txcol = $this->labelfontcolour; if ($txcol->isContrast()) { if ($labelFillColour->isRealColour()) { $txcol = $labelFillColour->getContrastingColour(); } else { wm_warn("You can't make a contrast with 'none'. [WMWARN43]\n"); $txcol = new WMColour(0, 0, 0); } } $map->myimagestring($node_im, $this->labelfont, $txt_x, $txt_y, $this->processedLabel, $txcol->gdAllocate($node_im), $this->labelangle); } $this->centre_x = $this->x - $bbox_x1; $this->centre_y = $this->y - $bbox_y1; $this->image = $node_im; }
else{ $retval=getzoomfactor($filename, $max_width, $max_height, $debug); $zoom_factor=$retval["zoom_factor"]; } if($debug!=0) echo "zoom_factor:$zoom_factor<br>"; $retval = imagesetresolution($filename, $zoom_factor); $img_small=$retval["image"]; */ if (isset($_SESSION["zoom_factor"])) { $zoom_factor = $_SESSION["zoom_factor"]; } else { $zoom_factor = 1; } $retval = imagecreatefromfile($filename); $img = $retval["img"]; $image_width = $retval["image_width"]; $image_height = $retval["image_height"]; if ($debug != 0) { print_r($retval); } //Bild drehen? if (isset($_SESSION["rotage"]) and !isset($_GET["norotage"])) { if ($_SESSION["rotage"] > 0 and $_SESSION["rotage"] < 360) { $rotage = $_SESSION["rotage"]; if ($debug != 0) { echo "Rotage: {$rotage}" . "°<br>"; } $img = imagerotate($img, 360 - $_SESSION["rotage"], 0); } else {
function imagesetresolution($filename, $zoom_factor) { //Rückgabewert $ret = array(); $ret["image"] = ""; $ret["error"] = ""; //Bildauflösung bestimmen $image_size = getimagesize($filename); $image_width = $image_size[0]; $img_source = imagecreatefromfile($filename); $image_height = $image_size[1]; //Load image $img_source = imagecreatefromfile($filename); //Calc new resolution $image_width_new = floor($image_width / $zoom_factor); $image_height_new = floor($image_height / $zoom_factor); if ($debug > 0) { echo "image_width:{$image_width}-image_height:{$image_height}<br>"; } $img_dst = ImageCreateTrueColor($image_width_new, $image_height_new); //Resample image if (!imagecopyresampled($img_dst, $img_source, 0, 0, 0, 0, $image_width_new, $image_height_new, $image_width, $image_height)) { $ret["error"] = "Error in function imagefilecrop: can not use imagecopyresampled()<br>"; $ret["image"] = $img_source; } else { $ret["error"] = ""; $ret["image"] = $img_dst; } return $ret; }
if ($original_aspect >= $thumb_aspect) { // If image is wider than thumbnail (in aspect ratio sense) $new_height = $thumb_height; $new_width = $width / ($height / $thumb_height); } else { // If the thumbnail is wider than the image $new_width = $thumb_width; $new_height = $height / ($width / $thumb_width); } $thumb = imagecreatetruecolor($thumb_width, $thumb_height); // Resize and crop imagecopyresampled($thumb, $image, 0 - ($new_width - $thumb_width) / 2, 0 - ($new_height - $thumb_height) / 2, 0, 0, $new_width, $new_height, $width, $height); //Barra if (trim($webdados_fb->options['fb_image_overlay_image']) != '') { $barra_url = parse_url(trim($webdados_fb->options['fb_image_overlay_image'])); $barra = imagecreatefromfile($_SERVER['DOCUMENT_ROOT'] . $barra_url['path']); imagecopy($thumb, $barra, 0, 0, 0, 0, intval(WEBDADOS_FB_W), intval(WEBDADOS_FB_H)); } header('Content-Type: image/jpeg'); imagejpeg($thumb, NULL, 95); imagedestroy($image); imagedestroy($thumb); imagedestroy($barra); } } } } } function imagecreatefromfile($filename) { if (!file_exists($filename)) {
/** * @return null|resource */ private function loadBackgroundImage($background) { $bgImageRef = null; // do the basic prep work if ($background != '') { if (is_readable($background)) { $bgImageRef = imagecreatefromfile($this->background); if (!$bgImageRef) { wm_warn("Failed to open background image. One possible reason: Is your BACKGROUND really a PNG?\n"); } else { $this->width = imagesx($bgImageRef); $this->height = imagesy($bgImageRef); wm_debug("Resizing map to background image (%dx%d)\n", $this->width, $this->height); } } else { wm_warn("Your background image file could not be read. Check the filename, and permissions, for {$background}\n"); } } return $bgImageRef; }
public function editProfileInformation_post() { //echo 'editProfileInformation'; $response = array(); $errors = array(); $response["meta"] = array('newToken' => array('name' => $this->security->get_csrf_token_name(), 'hash' => $this->security->get_csrf_hash())); if ($this->aauth->is_loggedin()) { if ($this->input->post('firstName')) { $firstname = $this->input->post('firstName'); $this->aauth->set_user_var('firstName', $firstname); } if ($this->input->post('lastName')) { $lastname = $this->input->post('lastName'); $this->aauth->set_user_var('lastName', $lastname); } if ($this->input->post('gender')) { $gender = $this->input->post('gender'); $this->aauth->set_user_var('gender', $gender); } if ($this->input->post('country')) { $country = $this->input->post('country'); $this->aauth->set_user_var('country', $country); } if ($this->input->post('occupation')) { $occupation = $this->input->post('occupation'); $this->aauth->set_user_var('occupation', $occupation); } if ($this->input->post('workStatus')) { $workstatus = $this->input->post('workStatus'); $this->aauth->set_user_var('workStatus', $workstatus); } if ($this->input->post('about')) { $about = $this->input->post('about'); $this->aauth->set_user_var('about', $about); } if ($_FILES and $_FILES['profilePicture']['name']) { $profilepicture = $this->input->post('profilePicture'); $this->load->library('image_lib'); // Image upload configs - change this stuff later $config['upload_path'] = FCPATH . '_tmp-folder/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = 1024 * 5; // 5MB $config['max_width'] = '5000'; $config['max_height'] = '5000'; $this->load->library('upload', $config); if (!$this->upload->do_upload("profilePicture")) { $errors[] = array("message" => $this->upload->display_errors()); } else { // Variables used later when resizing an image $originalFileUploadPath = $this->upload->data()['full_path']; $originalFileUploadFilePath = $this->upload->data()['file_path']; $originalFileRawName = $this->upload->data()['raw_name']; $originalFileExt = $this->upload->data()['file_ext']; // resize the original image to various sizes $config['image_library'] = 'GD2'; $config['source_image'] = $originalFileUploadPath; $sizes = array(array('width' => 16, 'height' => 16), array('width' => 250, 'height' => 250)); $fileNameForResizedImage = md5(microtime()) . '.jpg'; foreach ($sizes as $size) { $config['width'] = $size['width']; $config['height'] = $size['height']; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = FALSE; $config['thumb_marker'] = '_' . $size['width']; $this->image_lib->clear(); $this->image_lib->initialize($config); if ($this->image_lib->resize()) { if ($size['width'] == 16 && $size['height'] == 16) { rename($originalFileUploadFilePath . $originalFileRawName . '_' . $size['width'] . $originalFileExt, FCPATH . 'uploads/favicon/' . $size['width'] . 'x' . $size['height'] . '/' . $fileNameForResizedImage); } else { rename($originalFileUploadFilePath . $originalFileRawName . '_' . $size['width'] . $originalFileExt, FCPATH . 'uploads/profile_pictures/' . $size['width'] . 'x' . $size['height'] . '/' . $fileNameForResizedImage); } } } $this->aauth->set_user_var('profilePicture', $fileNameForResizedImage); } } if ($_FILES and $_FILES['profileHeaderImage']['name']) { $profileheaderimage = $this->input->post('profileHeaderImage'); $this->load->library('image_lib'); // Image upload configs - change this stuff later $config['upload_path'] = FCPATH . '_tmp-folder/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = 1024 * 5; // 5MB $config['max_width'] = '5000'; $config['max_height'] = '5000'; $this->load->library('upload', $config); if (!$this->upload->do_upload("profileHeaderImage")) { $errors[] = array("message" => "Upload failed."); } else { // Variables used later when resizing an image $originalFileUploadPath = $this->upload->data()['full_path']; $originalFileUploadFilePath = $this->upload->data()['file_path']; $originalFileRawName = $this->upload->data()['raw_name']; $originalFileExt = $this->upload->data()['file_ext']; // Convert the image to a grayscaled version $this->load->helper('image_helper'); $im = imagecreatefromfile($originalFileUploadPath); if ($im && imagefilter($im, IMG_FILTER_GRAYSCALE)) { $response["message"] = "Profile information saved."; imagejpeg($im, $originalFileUploadPath); } else { $errors[] = array("message" => "Conversion to grayscale failed."); } imagedestroy($im); // resize the original image to various sizes $config['image_library'] = 'GD2'; $config['source_image'] = $originalFileUploadPath; $sizes = array(array('width' => 1170, 'height' => 500)); $fileNameForResizedImage = md5(microtime()) . '.jpg'; foreach ($sizes as $size) { $config['width'] = $size['width']; $config['height'] = $size['height']; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = FALSE; $config['thumb_marker'] = '_' . $size['width']; $this->image_lib->clear(); $this->image_lib->initialize($config); if ($this->image_lib->resize()) { rename($originalFileUploadFilePath . $originalFileRawName . '_' . $size['width'] . $originalFileExt, FCPATH . 'uploads/header_images/' . $size['width'] . 'x' . $size['height'] . '/' . $fileNameForResizedImage); } } $this->aauth->set_user_var('headerImage', $fileNameForResizedImage); } } if ($this->input->post('profileTextColour')) { $profiletextcolour = $this->input->post('profileTextColour'); $this->aauth->set_user_var('profileTextColour', $profiletextcolour); } if ($this->input->post('profileForecolor')) { $profileforecolor = $this->input->post('profileForecolor'); $this->aauth->set_user_var('profileForecolor', $profileforecolor); } $response["message"] = "Profile information saved."; } else { $this->response("Not authorised", REST_Controller::HTTP_UNAUTHORIZED); return false; } $response["errors"] = $errors; $this->response($response, REST_Controller::HTTP_OK); }