Skip to content

Commit fabb086

Browse files
committed
Add composer and adjust the path of demo
1 parent 80e1778 commit fabb086

File tree

4 files changed

+71
-8
lines changed

4 files changed

+71
-8
lines changed

ImageResize.php

+47-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
/**
3+
* Copyright (c) 2019 PHP-QuickORM ImageResize
4+
* Author: Rytia Leung
5+
6+
* Github: github.com/php-quickorm/ImageResize
7+
*/
8+
29
class ImageResize
310
{
411
private $path;
@@ -10,6 +17,13 @@ class ImageResize
1017
private $rawResource;
1118
private $newResource;
1219

20+
/**
21+
* ImageResize constructor.
22+
* @param string $path
23+
* @param int $width
24+
* @param int $height
25+
* @param string $sourceFormat
26+
*/
1327
public function __construct($path, $width = 170, $height = 128, $sourceFormat = null)
1428
{
1529

@@ -31,6 +45,9 @@ public function __construct($path, $width = 170, $height = 128, $sourceFormat =
3145
$this->generate();
3246
}
3347

48+
/**
49+
* Generate image
50+
*/
3451
private function generate(){
3552
// Get new sizes
3653
list($oldWidth, $oldHeight) = getimagesize($this->path);
@@ -63,6 +80,15 @@ private function generate(){
6380

6481
}
6582

83+
/**
84+
* Add water mark to image
85+
* @param string $path
86+
* @param int $width
87+
* @param int $height
88+
* @param string $positionX
89+
* @param string $positionY
90+
* @param int $margin
91+
*/
6692
public function addImageMark($path, $width = 50, $height = 50, $positionX = "right", $positionY = "bottom", $margin = 10){
6793

6894
$im = (new ImageResize($path, $width, $height))->getImageResource();
@@ -83,6 +109,15 @@ public function addImageMark($path, $width = 50, $height = 50, $positionX = "rig
83109

84110
}
85111

112+
/**
113+
* Add text to image
114+
* @param string $text
115+
* @param int $fontSize
116+
* @param string $color
117+
* @param string $positionX
118+
* @param string $positionY
119+
* @param int $margin
120+
*/
86121
public function addTextMark($text, $fontSize = 5, $color = "#0000ff", $positionX = "right", $positionY = "bottom", $margin = 10){
87122

88123
$textWidth = imagefontwidth($fontSize) * strlen($text);
@@ -105,13 +140,21 @@ public function addTextMark($text, $fontSize = 5, $color = "#0000ff", $positionX
105140
imagestring ( $this->newResource , $fontSize, $dstX , $dstY , $text , $textColor );
106141
}
107142

143+
/**
144+
* Get PHP GD resource
145+
* @return resource
146+
*/
108147
public function getImageResource()
109148
{
110149
return $this->newResource;
111150
}
112151

113152

114-
153+
/**
154+
* Save the image as file
155+
* @param string $path
156+
* @param null $format
157+
*/
115158
public function save($path, $format = null){
116159

117160
if (is_null($format)) {
@@ -137,6 +180,9 @@ public function save($path, $format = null){
137180

138181
}
139182

183+
/**
184+
* Send HTTP Response
185+
*/
140186
public function render(){
141187
switch ($this->extension){
142188
case 'jpg' :

composer.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "php-quickorm/image-resize",
3+
"description": "A library implemented by PHP to resize image and add water mark",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Rytia",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {}
13+
}

demo/index.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2019 PHP-QuickORM ImageResize
4+
*/
5+
6+
require_once '../ImageResize.php';
7+
8+
$a = new ImageResize(realpath('../Windows.jpg'),800,600);
9+
$a->addTextMark("zzfly.net", 5, "#cccccc", "right", "bottom",10);
10+
$a->addImageMark(realpath('../Windows.jpg'),100,80,"right","bottom",50);
11+
$a->render();

index.php

-7
This file was deleted.

0 commit comments

Comments
 (0)