Why do I keep getting the wrong color? - powershell

I am trying to change the color of all the arrows in a document to red. However, they keep changing to blue.
I tried this:
$shapes = $doc.Shapes
foreach ($shape in $doc.Shapes) {
if($shape.Name -like "Straight Arrow Connector*"){
$red = [System.Drawing.Color]::FromArgb(255,255,0,0)
$shape.Line.ForeColor.RGB = $red.ToArgb()
}
}
From the comment below, this ended up fixing my issue:
$shapes = $doc.Shapes
$color = [System.Drawing.Color]::Red
$red = $color.R + 0x100 * $color.G + 0x10000 * $color.B
foreach ($shape in $doc.Shapes) {
if($shape.Name -like "Straight Arrow Connector*"){
$shape.Line.ForeColor.RGB = $red
}
}

Related

autocomplete in datagridviewcell

I have a datagridview control and would like in one of the cells to make use of autocomplete.
I tried using the editcontrolshowing event but cant really get it to work.
$DGVtimeAttendance_EditingControlShowing = [System.Windows.Forms.DataGridViewEditingControlShowingEventHandler]{
$queryGetaLLuSERS = "SELECT CONCAT(firstname,' ',lastname) AS Employee
FROM tbl_user"
$queryGetaLLuSERS = sql_query -Query $queryGetaLLuSERS
$getheaderText = $DGVtimeAttendance.Columns[1].HeaderText
if ($getheaderText -eq 'Employee')
{
#$getvalueChanged = $this.Rows[$_.RowIndex].Cells[$_.ColumnIndex].value
#Write-Host $getvalueChanged
$autotext = New-Object System.Windows.Forms.DataGridViewTextBoxEditingControl
$autotext.AutoCompleteMode = 'Suggest'
$autotext.AutoCompleteSource = 'CustomSource'
$autotext.AutoCompleteCustomSource.AddRange($queryGetaLLuSERS.employee)
$DGVtimeAttendance.Controls.add($autotext)
#$_.Control.autocompleteMode = 'Suggest'
Write-Host $_
}}
with the help from santiagos post
i changed the if statement to
if ($getheaderText -eq 'Employee')
{
$this.EditingControl.AutoCompleteMode = [System.Windows.Forms.AutoCompleteMode]::Suggest
$this.EditingControl.AutoCompleteSource = [System.Windows.Forms.AutoCompleteSource]::CustomSource
$this.EditingControl.AutoCompleteCustomSource.AddRange(($queryGetaLLuSERS.employee)) #= [System.Windows.Forms.AutoCompleteSource]::CustomSource
}
and worked like a charm
thx everyone and especially santiago

Is it possible to create specific constant elements of a PowerShell array?

Let's say I have array Grid that was initialized with
$Grid = #(#(1..3), #(4..6), #(7..9))
and I want to change Grid[0][0] to value "Test" but I want to make it unchangeable, is there a way I could to that?
So far I've tried playing around with classes that allow read-only or constant declarations through the class as opposed to using New-Variable/Set-Variable but it doesn't affect the index itself but the individual element as in
$Grid[0][0] = [Array]::AsReadOnly(#(1,2,3))
$Grid[0][0] # 1 \n 2 \n 3
$Grid[0][0].IsReadOnly # True
$Grid[0][0] = "test"
$Grid[0][0] # test
I assume this is due to $Grid[0][0] being read-only as opposed to constant and the behaviour I experienced supported that:
$test = [Array]::AsReadOnly(#(1,2,3,4))
$test[0]=1 # Errors
$test = "test"
$test # test
$Grid = #(#(1..3), #(4..6), #(7..9))
$Grid[0][0] = [Array]::AsReadOnly(#(1,2,3))
$Grid[0][0][0] = 1 # Errors
$Grid[0][0] = "test"
$Grid[0][0] # test
I'm not sure what to try next and I know that this is very simple with classes but I am not looking for that as a solution.
You'll have to make both dimensions of your nested array read-only to prevent anyone from overwriting $grid[0]:
$grid =
[array]::AsReadOnly(#(
,[array]::AsReadOnly(#(1,2,3))
,[array]::AsReadOnly(#(3,2,1))
))
(the unary , is not a typo, it prevents PowerShell from "flattening" the resulting read-only collection)
Now $grid should behave as you expect:
$grid[0] # 1,2,3
$grid[0][0] # 1
$grid[0][0] = 4 # error
$grid[0] = 4 # error
If you want to be able to prevent writing to individual "cells", you'll have to define a custom type:
using namespace System.Collections
class Grid {
hidden [int[,]] $data
hidden [bool[,]] $mask
Grid([int]$width,[int]$height){
$this.mask = [bool[,]]::new($width, $height)
$this.data = [int[,]]::new($width, $height)
}
[int]
Get([int]$x,[int]$y)
{
if(-not $this.CheckBounds($x,$y)){
throw [System.ArgumentOutOfRangeException]::new()
}
return $this.data[$x,$y]
}
Set([int]$x,[int]$y,[int]$value)
{
if(-not $this.CheckBounds($x,$y)){
throw [System.ArgumentOutOfRangeException]::new()
}
if(-not $this.mask[$x,$y])
{
$this.data[$x,$y] = $value
}
else
{
throw [System.InvalidOperationException]::new("Cell [$x,$y] is currently frozen")
}
}
Freeze([int]$x,[int]$y)
{
if(-not $this.CheckBounds($x,$y)){
throw [System.ArgumentOutOfRangeException]::new()
}
$this.mask[$x,$y] = $true
}
Unfreeze([int]$x,$y)
{
if(-not $this.CheckBounds($x,$y)){
throw [System.ArgumentOutOfRangeException]::new()
}
$this.mask[$x,$y] = $false
}
hidden [bool]
CheckBounds([int]$x,[int]$y)
{
return (
$x -ge $this.data.GetLowerBound(0) -and
$x -le $this.data.GetUpperBound(0) -and
$y -ge $this.data.GetLowerBound(1) -and
$y -le $this.data.GetUpperBound(1)
)
}
}
Now you can do:
$grid = [Grid]::new(5,5)
$grid.Set(0, 0, 1) # Set cell value
$grid.Get(0, 0) # Get cell value
$grid.Freeze(0, 0) # Now freeze cell 0,0
$grid.Set(0, 0, 2) # ... and this will now throw an exception
$grid.Set(0, 1, 1) # Setting any other cell still works
If you want native support for index expressions (ie. $grid[0,0]), the Grid class will need to implement System.Collections.IList

How can set up the table correctly for receiving the string converted from dates?

I have a problem and don't know how to solve it. After i run the code i didn't receive corectly a period of time. I put the code here.
I think something is wrong with table from database (i use PhpMyAdmin 4.2.0 module from EasyPhp). I put an image too to see what happens. The dates marked with red need to be at the end of table.
<?php
function data_range($first, $last, $step = '+1 day', $output - format = 'd-m-Y')
{
$dates = array();
$current = strtotime($first);
$last = strtotime($last);
while ($current <= $last)
{
$dates[] = date($output_format, $current);
$current = strtotime($step, $current);
}
foreach($dates as $zile)
{
$krr = explode('-', $zile);
var_dump($krr);
$result2 = implode('/', $krr);
echo $result2 . "<br/>";
$sql4 = "INSERT INTO studenti3 (data) VALUES ('$result2')";
$rez4 = mysql_query($sql4);
}
var_dump($dates);
}
$first = "06-04-2015";
$last = "07-05-2015";
$step = "+1day";
$output_format = 'd-m-Y';
date_range($first, $last, $step, $output_format); ?>

Why isn't my og:image picture updated properly on Facebook?

Hello all and thanks in advance for your help. Our website, Tom's Guide France has recently changed its logo.
Therefore, we updated the picture file that was linked in our og:image meta on pages not having a specific one.
Example URL : http://www.tomsguide.fr/solutions/id-2109117/desimlockage-dallas-urgent.html
The picture for the og:image meta is the following : http://m.bestofmedia.com/sfp/images/design/logos/fb/tgu_pic.jpg
For me, it's a text logo with an up/down arrow instead of the letter I.
But for Facebook, it's our old logo, with a torchlight.
I used the debugger for both those URL.
But in both cases, Facebook keeps seeing my old logo.
Any hint ?
Best,
Gzav
public static function resize_img($srcimg,$dest_img,$max_width=0,$max_height=0) {
$save = $dest_img;
$src = null;
$source_pic = $srcimg;
$imageinfo = getimagesize($source_pic);
//print_r($imageinfo);die;
switch($imageinfo['mime'])
{
case 'image/png':
$src = imagecreatefrompng($source_pic);
break;
case 'image/jpeg':
$src = imagecreatefromjpeg($source_pic);
break;
case 'image/gif':
$src = imagecreatefromgif($source_pic);
break;
case 'image/x-ms-bmp':
$src = imagecreatefrombmp($source_pic);
break;
}
list($width,$height) = getimagesize($source_pic);
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if( ($width <= $max_width) && ($height <= $max_height) ){
$tn_width = $width;
$tn_height = $height;
}
elseif($y_ratio == 0){
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
elseif($x_ratio == 0){
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
elseif (($x_ratio * $height) < $max_height){
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
// $ext = strtolower(array_pop(explode(".", $srcimg)));
$ext=substr($srcimg,-3,3);
//ini_set('memory_limit', '32M');
$tmp=imagecreatetruecolor($tn_width,$tn_height);
//print_r($tmp.$src);die;
imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);
if(($ext=="jpg") || ($ext=="jpeg"))
{
$ye = imagejpeg($tmp, $save, 100) ;
}
if($ext=="gif"){ imagegif($tmp, $save) ; }
if($ext=="bmp"){ imagebmp($tmp, $save) ; }
if($ext=="png"){
//imagecolortransparent($tmp, imagecolorallocate($tmp,0,0,0));
imagepng($tmp, $save, 9) ;
}
}
$this->resize_img($siurcename,$dest_img2,83,83);//calling function

Uploading transparent images adds a black background

I am trying to make a function to handle avatar uploads.
My problem is, when I upload a transparent image, it turned everything which is transparent black after I resize it.
I have tried using the imagesavealpha() & imagealphablending() options, but the background is still turning black.
It might just be me being blind and not seeing the problem in the code, but I have no idea why it does this.
I can confirm that after the image has been moved to the image/avatars folder just after being uploaded, the background is still transparent.
this is my current code, I have been testing with .png images:
function upload_avatar(){
$base_path = SYSTEM_PATH;
if($_FILES['avatar_img']['tmp_name'] != '') {
$id = md5($this->user_id());
$filename = $_FILES['avatar_img']['name'];
$file_basename = substr($filename, 0, strripos($filename, '.')); // strip extention
$file_ext = substr($filename, strripos($filename, '.')); // strip name
$filesize = $_FILES['avatar_img']['size'];
$newfilename = $id . $file_ext;
if ($file_ext == ".jpg" || $file_ext == ".JPG" || $file_ext == ".jpeg" || $file_ext == ".png" || $file_ext == ".gif"){
if($filesize <= 153600){
move_uploaded_file($_FILES['avatar_img']['tmp_name'], $base_path."/images/avatars/" . $newfilename);
//resize image form
list($width, $height) = getimagesize($base_path."/images/avatars/" . $newfilename);
$scale_height = $height/$width;
$scale_width = $width/$height;
//Find height and width of the image
if($width > $height && $width > 150){
$width_new = 150;
$height_new = round($width_new*$scale_height);
}else if($height > $width && $height > 150){
$height_new = 150;
$width_new = round($height_new*$scale_width);
}else{
$height_new = $height;
$width_new = $width;
}
switch($file_ext) {
case ".jpg" :
case ".jpeg":
$source = imagecreatefromjpeg($base_path."/images/avatars/" . $newfilename);
break;
case ".png" :
$source = imagecreatefrompng($base_path."/images/avatars/" . $newfilename);
break;
default:
$source = imagecreatefromgif($base_path."/images/avatars/" . $newfilename);
break;
}
$destination = imagecreatetruecolor($width_new, $height_new);
imagesavealpha($destination, true);
imagealphablending($destination, true);
imagecopyresized($destination, $source, 0, 0, 0, 0, $width_new, $height_new, $width, $height);
switch($file_ext) {
case ".jpg":
case ".jpeg":
imagejpeg($destination, $base_path."/images/avatars/" . $newfilename, 85);
break;
case ".png":
imagepng($destination, $base_path."/images/avatars/" . $newfilename, 8);
break;
default:
imagegif($destination, $base_path."/images/avatars/" . $newfilename, 85);
break;
}
return $newfilename;
}else{
$this->upload_avatar = '<br />But the avatar was not updated. The avatar\'s size exceeded the 150kb limit. ';
return '';
}
}else{
$this->upload_avatar = '<br />But the avatar was not updated. The avatar must be one of the following formats: jpg, jpeg, png or gif. ';
return '';
}
}else{
return '';
}
}
Any help would be appreciated as I am going nuts looking at this now.
Thanks!
This here may be what you're looking for. The second comment contains an example of resizing pngs and gifs while preserving transparency.
p.s. I'd have added this as a comment but I don't have the rights to do that yet.