public static function Move($image, $outtype = "png", $raw = false) { if (!$raw) { list($size["x"], $size["y"]) = getimagesize($image); } else { list($size["x"], $size["y"]) = getimagesizefromstring($image); } $data = RandImg::loadImage($image, $raw); $move_x = rand(0, $size["x"]); $move_y = rand(0, $size["y"]); $new_data = imagecreatetruecolor($size["x"], $size["y"]); imagecopy($new_data, $data, 0, 0, $size["x"] - $move_x, $size["y"] - $move_y, $move_x, $move_y); imagecopy($new_data, $data, $move_x, 0, 0, $size["y"] - $move_y, $size["x"] - $move_x, $move_y); imagecopy($new_data, $data, 0, $move_y, $size["x"] - $move_x, 0, $move_x, $size["y"] - $move_y); imagecopy($new_data, $data, $move_x, $move_y, 0, 0, $size["x"] - $move_x, $size["y"] - $move_y); return array("image" => RandImg::makeImageString($new_data, $outtype), "move_x" => $move_x, "move_y" => $move_y); }
private function randomizeImage($path, $options, $header = true) { $type = RandImg::getImageType($path); $image = file_get_contents($path); list($size["x"], $size["y"]) = getimagesizefromstring($image); $atributes = array(); $css_rules = array(); $json_options = array(); if ($this->format == "img") { $atributes["width"] = $size["x"]; $atributes["height"] = $size["y"]; } elseif ($this->format == "bg") { $css_rules["width"] = $size["x"] . "px"; $css_rules["height"] = $size["y"] . "px"; } foreach ($options as $option) { if ($option['name'] == 'hmirror') { $image = RandImg::Mirror($image, $type, true, false); } else { if ($option['name'] == 'vmirror') { $image = RandImg::Mirror($image, $type, true, true); } else { if ($option['name'] == 'invert') { $image = RandImg::Invert($image, $type, true); if ($this->format == "img") { $atributes["style"] = "-webkit-filter: invert(100%);"; } elseif ($this->format == "bg") { $css_rules["-webkit-filter"] = "invert(100%)"; } } else { if ($option['name'] == 'grayscale') { $image = RandImg::Grayscale($image, $type, true); } else { if ($option['name'] == 'crop') { $image = RandImg::Crop($image, $type, true); if ($this->format == "image" || $this->format == "convert") { $image = $image["image"]; } elseif ($this->format == "img") { $atributes["width"] = intval($image["width"]); $atributes["height"] = intval($image["height"]); $image = $image["image"]; } elseif ($this->format == "bg") { $css_rules["width"] = intval($image["width"]) . "px"; $css_rules["height"] = intval($image["height"]) . "px"; $image = $image["image"]; } } else { if ($option['name'] == 'fixresize') { $image = RandImg::Resize($image, $type, true, true); if ($this->format == "image" || $this->format == "convert") { $image = $image["image"]; } elseif ($this->format == "img") { $atributes["width"] = intval($image["width"]); $atributes["height"] = intval($image["height"]); $image = $image["image"]; } elseif ($this->format == "bg") { $css_rules["width"] = intval($image["width"]) . "px"; $css_rules["height"] = intval($image["height"]) . "px"; $image = $image["image"]; } } else { if ($option['name'] == 'resize') { $image = RandImg::Resize($image, $type, true, false); if ($this->format == "image" || $this->format == "convert") { $image = $image["image"]; } elseif ($this->format == "img") { $atributes["width"] = intval($image["owidth"]); $atributes["height"] = intval($image["oheight"]); $image = $image["image"]; } elseif ($this->format == "bg") { $css_rules["width"] = intval($image["owidth"]) . "px"; $css_rules["height"] = intval($image["oheight"]) . "px"; $css_rules["background-size"] = $image["owidth"] . "px " . $image["oheight"] . "px"; $image = $image["image"]; } } else { if ($option['name'] == 'rotate') { $image = RandImg::Rotate($image, $type, true); if ($this->format == "image" || $this->format == "convert") { $image = $image["image"]; } elseif ($this->format == "img") { $atributes["width"] = intval($image["width"]); $atributes["height"] = intval($image["height"]); $image = $image["image"]; } elseif ($this->format == "bg") { //$css_rules["transform"]="rotate(".(-1*$image["angle"])."deg)"; //$css_rules["-webkit-transform"]="rotate(".(-1*$image["angle"])."deg)"; //коррекцио оставим на будущее $image = $image["image"]; } } else { if ($option['name'] == 'border') { $image = RandImg::Border($image, $type, true); if ($this->format == "image" || $this->format == "convert") { $image = $image["image"]; } elseif ($this->format == "img") { $atributes["width"] = intval($image["width"]); $atributes["height"] = intval($image["height"]); $image = $image["image"]; } elseif ($this->format == "bg") { $css_rules["width"] = intval($image["width"]) . "px"; $css_rules["height"] = intval($image["height"]) . "px"; $image = $image["image"]; } } else { if ($option['name'] == 'sharp') { $image = RandImg::Sharp($image, $type, true); } else { if ($option['name'] == 'blur') { $image = RandImg::Blur($image, $type, true); } else { if ($option['name'] == 'eskiz') { $image = RandImg::Eskiz($image, $type, true); } else { if ($option['name'] == 'pixelization') { $image = RandImg::Pixelization($image, $type, true); } else { if ($option['name'] == 'move') { $image = RandImg::Move($image, $type, true); if ($this->format == "image" || $this->format == "img" || $this->format == "convert") { $image = $image["image"]; } elseif ($this->format == "bg") { $css_rules["background-position-x"] = "-" . intval($image["move_x"]) . "px"; $css_rules["background-position-y"] = "-" . intval($image["move_y"]) . "px"; $image = $image["image"]; } } } } } } } } } } } } } } } } if ($this->format == "convert") { return $image; } if ($header && $this->format == "image") { header('Content-Type: image/' . $type); return $image; } if ($this->format == "img") { //сохраним картинку в папку кэша $filename = time() . "." . $type; $dir = 'http://' . $_SERVER['HTTP_HOST'] . pathinfo($this->URL, PATHINFO_DIRNAME) . "/" . $this->cachePath; $dir = str_replace('\\/', '/', $dir); file_put_contents($this->cachePath . $filename, $image); $html = "<img src='" . $dir . $filename . "' "; foreach ($atributes as $atribute => $value) { $html .= $atribute . "='" . $value . "' "; } $html .= ">"; return $html; } if ($this->format == "bg") { //сохраним картинку в папку кэша $filename = time() . "." . $type; $dir = 'http://' . $_SERVER['HTTP_HOST'] . pathinfo($this->URL, PATHINFO_DIRNAME) . "/" . $this->cachePath; $dir = str_replace('\\/', '/', $dir); file_put_contents($this->cachePath . $filename, $image); $html = "background='" . $dir . $filename . "' style='"; foreach ($css_rules as $rule => $value) { $html .= $rule . ":" . $value . ";"; } $html .= "'"; return $html; } return $image; }