Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
Helpers
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Modulus
Helpers
Commits
afd45d39
Commit
afd45d39
authored
Apr 01, 2020
by
Sylvain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout helper Image
parent
f816d73c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
1 deletion
+79
-1
src/impage.php
src/impage.php
+78
-0
src/str.php
src/str.php
+1
-1
No files found.
src/impage.php
0 → 100644
View file @
afd45d39
<?php
use
Illuminate\Support\Facades\File
;
use
Intervention\Image\Facades\Image
;
if
(
!
function_exists
(
'optimize_image'
))
{
/**
* Conversion et optimisation d'une image
* @param string $path_image chemin vers l'image
* @param integer $width Largeur de l'image
* @param integer $height Hauteur de l'image (null pour automatique)
* @param string $type Type mime de l'image
* @param integer $quality Qualité de l'image, niveau de compression
* @return void
*/
function
optimize_image
(
$path_image
,
$width
=
1920
,
$height
=
null
,
$type
=
'jpg'
,
$quality
=
80
)
{
// On défini les format d'image accepté
$imageMimeTypes
=
[
'image/jpeg'
,
'image/gif'
,
'image/png'
];
if
(
!
File
::
isFile
(
$path_image
)
||
!
in_array
(
mime_content_type
(
$path_image
),
$imageMimeTypes
))
{
return
false
;
}
$img
=
Image
::
make
(
$path_image
);
$img
->
resize
(
$width
,
$height
,
function
(
$constraint
)
{
$constraint
->
aspectRatio
();
$constraint
->
upsize
();
});
$img
->
encode
(
$type
,
$quality
);
$img
->
save
();
}
}
/**
* Fonction pour générer des miniatures d'image
*/
if
(
!
function_exists
(
'make_thumb_image'
))
{
/**
* Conversion en miniature d'une image
* @param string $path_image chemin vers l'image
* @param integer $width Largeur de l'image
* @param integer $height Hauteur de l'image (null pour automatique)
* @param string $type Type mime de l'image
* @param integer $quality Qualité de l'image, niveau de compression
* @return void
*/
function
make_thumb_image
(
$path_image
,
$width
=
200
,
$height
=
null
,
$type
=
'jpg'
,
$quality
=
80
)
{
$imageMimeTypes
=
[
'image/jpeg'
,
'image/gif'
,
'image/png'
];
if
(
!
File
::
isFile
(
$path_image
)
||
!
in_array
(
mime_content_type
(
$path_image
),
$imageMimeTypes
))
{
return
false
;
}
$img
=
Image
::
make
(
$path_image
);
$filename
=
$img
->
filename
.
'_thumb.'
.
$format
;
$pathname
=
$img
->
dirname
.
'/'
.
$filename
;
$img
->
resize
(
$width
,
$height
,
function
(
$constraint
)
{
$constraint
->
aspectRatio
();
$constraint
->
upsize
();
});
$img
->
encode
(
$type
,
$quality
);
$img
->
save
(
$pathname
);
return
$pathname
;
}
}
src/str.php
View file @
afd45d39
...
...
@@ -96,7 +96,7 @@ if ( !function_exists('str_indent')) {
}
}
if
(
!
function_exists
(
'str
ingToArrayArgs
'
))
{
if
(
!
function_exists
(
'str
_args_to_array
'
))
{
/**
* Converti une chaine d'arguments en tableau d'arguments en respectant le typage
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment