Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
ncphp
/
mcClasses
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3cd29237
authored
Jul 30, 2014
by
sn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mcImagick kann jetzt thumbnail
1 parent
ec738e92
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
0 deletions
file/class_mcImagick.inc.php
file/class_mcImagick.inc.php
View file @
3cd2923
...
@@ -22,5 +22,85 @@ class mcImagick {
...
@@ -22,5 +22,85 @@ class mcImagick {
}
}
/**
* Calculate new image dimensions to new constraints
*
* @param Original X size in pixels
* @param Original Y size in pixels
* @return New X maximum size in pixels
* @return New Y maximum size in pixels
* http://php.net/manual/de/imagick.thumbnailimage.php
*/
private
static
function
scaleImage
(
$x
,
$y
,
$cx
,
$cy
)
{
//Set the default NEW values to be the old, in case it doesn't even need scaling
list
(
$nx
,
$ny
)
=
array
(
$x
,
$y
);
//If image is generally smaller, don't even bother
if
(
$x
>=
$cx
||
$y
>=
$cx
)
{
//Work out ratios
if
(
$x
>
0
)
$rx
=
$cx
/
$x
;
if
(
$y
>
0
)
$ry
=
$cy
/
$y
;
//Use the lowest ratio, to ensure we don't go over the wanted image size
if
(
$rx
>
$ry
)
{
$r
=
$ry
;
}
else
{
$r
=
$rx
;
}
//Calculate the new size based on the chosen ratio
$nx
=
intval
(
$x
*
$r
);
$ny
=
intval
(
$y
*
$r
);
}
//Return the results
return
array
(
$nx
,
$ny
);
}
public
static
function
makeThumbnail
(
$param_original_filepath
,
$param_thumbnail_filepath
,
$param_maximumWidth
=
100
,
$param_maximumHeight
=
100
)
{
if
(
file_exists
(
$param_original_filepath
))
{
//Read original image and create Imagick object
try
{
$thumb
=
new
Imagick
(
$param_original_filepath
);
}
catch
(
Exception
$e
)
{
D
::
li
(
'Exception abgefangen: '
.
$e
->
getMessage
());
return
false
;
}
try
{
//Work out new dimensions
list
(
$newX
,
$newY
)
=
mcImagick
::
scaleImage
(
$thumb
->
getImageWidth
(),
$thumb
->
getImageHeight
(),
$param_maximumWidth
,
$param_maximumHeight
);
//Scale the image
$thumb
->
thumbnailImage
(
$newX
,
$newY
);
}
catch
(
Exception
$e
)
{
D
::
li
(
'Exception abgefangen: '
.
$e
->
getMessage
());
return
false
;
}
$create
=
mcDir
::
create
(
dirname
(
$param_thumbnail_filepath
));
//Write the new image to a file
try
{
$thumb
->
writeImage
(
$param_thumbnail_filepath
);
}
catch
(
Exception
$e
)
{
D
::
li
(
'Exception abgefangen: '
.
$e
->
getMessage
());
return
false
;
}
if
(
file_exists
(
$param_thumbnail_filepath
))
{
return
true
;
}
else
{
return
false
;
}
}
else
{
return
false
;
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment