-
Notifications
You must be signed in to change notification settings - Fork 1
Actions Methods
copy(mixed $value)
This function will generate new copies based on the model image. This function accepts only integers greater than 0 or matrix.
By using integers, you are defining how many copies the function should generate. Like this:
EditImage::from('images/zacarias.jpg')->copy(3)->save()
In this example the script is generating four images. The first was generated with from()
and the others with copy()
By using arrays, you are defining how many copies the function should generate and yours alias. Like this:
BuildImage::from('images/zacarias.jpg', 'alias0')->copy(['alias1', 'alias2', 'alias3'])->save()
In the first example, you have alias like this: [0,1,2,3]
In the second example, the script is generating four images too. But in this cases, you have alias on strings. Like this:
['alias0', 'alias1', 'alias2', 'alias3']
path(string $path, mixed $alias = false)
This function sets the path, file name and extension to be saved.
When this function is not used, the file will be saved to the same path as the model image.
If you are using an image from a URL, this function is required.
EditImage::from('images/zacarias.jpg')->path('other_path/zac.png')->save()
In this example the path function will save the image to other_path/
, file name will be zac
and its extension will be .png
resize(string $size, mixed $alias = false)
This function resize image using string commands.
The commands is simple:
'WxH'
where W is a width value and H is a height value. You can use a integer number in this values or symbols.
Integers will have the value in pixels. Therefore, if you use '300x200'
, the value will be width: 300px
and height: 200px
.
You have 2 options for symbols: *
or _
The symbol *
means that the width or height will be proportional to the value (W or H) and the structure of the image.
The symbol _
means that the height or width will be the 100% value of the image.
This image have a 400x543px
.
Using this code:
EditImage::
from('rabbit.png')
->resize('200x*') // string commands
->save();
the image will be 200x271px because this is the proportion of the model image. Look:
crop(string $values, mixed $alias = false)
This function crop image using string commands.
The commands is this:
'posx posy WxH'
where W is a width value and H is a height value. You can use a integer number in this values or symbols.
(See more about symbols in resize())
The posx posy is the position of the marker that will crop the image.
The posx can be a integer or a string (left
or center
or right
) and posy can be a integer or a string (top
or center
or bottom
)
The following table illustrates all possible combinations using string:
left top | center top | right top |
left center | center center | right center |
left bottom | center bottom | right bottom |
When the integer is used in posx it behaves like a margin-left. Equating the integer is used in posy it behaves like a margin-top. See the image below with the code example:
->crop('20 10 230x150')
// posx posy WxH
You can also combine string with numbers. Example:
->crop('left 10 230x150')
// posx posy WxH
This code acts on the image as follows:
EditImage::
from('images/turtle.jpg', 'cropped')
->crop('center top 246x139')
->save();
And result will be:
flip(string $flip, mixed $alias = false)
This function flips the image using string commands.
The commands can be 'horizontal', 'vertical' or 'both'.
EditImage::
from('images/turtle.jpg')
->flip('both')
->save();
use(string $method, array $vars)
This function will help make the code more cohesive and work with more than one image at a time.
Imagine you have 5 copies, and they all need to be saved in different directories. Could you do this:
EditImage::
from('images/turtle.jpg', 'img1')
->copy(['img2', 'img3', 'img4', 'img5'])
->path('path1/turtle_copy.jpg'. 'img1') // path diferent
->path('path2/turtle_copy.jpg', 'img2') // path diferent
->path('path3/turtle_copy.jpg', 'img3') // path diferent
->path('path4/turtle_copy.jpg', 'img4') // path diferent
->path('path5/turtle_copy.jpg', 'img5') // path diferent
->flip('horizontal')
->save();
Or this:
EditImage::
from('images/turtle.jpg', 'img1')
->copy(['img2', 'img3', 'img4', 'img5'])
->use('path', [
'img1' => 'path1/turtle_copy.jpg',
'img2' => 'path2/turtle_copy.jpg',
'img3' => 'path3/turtle_copy.jpg',
'img4' => 'path4/turtle_copy.jpg',
'img5' => 'path5/turtle_copy.jpg'
])
->flip('horizontal')
->save();
Both options have the same performance.