Permalink
Browse files

Use imagick to resize jpg/png

This should fix the problem of transparant png's resizing incorrectly.
This change is not retroactive, images that have been uploaded in the past
will not be affected
  • Loading branch information...
r04r committed Nov 1, 2015
1 parent 12502b4 commit c06ddd389fcf8b6bf9b5e6e4ede90d28185a533e
Showing with 29 additions and 28 deletions.
  1. +2 −2 events.php
  2. +1 −0 includes/ChromePhp.php
  3. +1 −0 includes/config.example.php
  4. +22 −23 includes/functions.php
  5. +1 −1 includes/template.php
  6. +1 −1 includes/upgrade.php
  7. +1 −1 topic.php
View
@@ -47,8 +47,8 @@
// Display the events menu and events.
echo '<ul class="menu">'; if (ALLOW_USER_EVENTS || allowed('manage_events')) {
echo '<li><a href="'.DOMAIN.'new_event">New event</a></li><li>';
}
echo '<li><a href="'.DOMAIN.'new_event">New event</a></li><li>';
}
echo'<a href="'.DOMAIN.'about_events">About</a></li>'; if (allowed('manage_events')) {
if (PRE_MODERATE_BULLETINS && ALLOW_USER_EVENTS) {
echo '<li><a href="'.DOMAIN.'moderate_events">Moderate events</li></a>';
View
@@ -42,3 +42,4 @@ public static function useFile()
}
}
//}
@@ -81,6 +81,7 @@
define('FANCY_IMAGE', true); // Use a fancy image viewer or not.
define('EMBED_VIDEOS', true); // Enable video (Youtube/Vimeo) embedding.
define('USE_GIFSICLE', false); // Use `gifsicle` command to resize gifs
define('USE_IMAGICK', true); // Use `convert` (imagick) command to resize png/jpg
// Styles
define('DEFAULT_STYLESHEET', 'violet'); // Default style, don't include the .css. extention, use the name only.
View
@@ -1661,28 +1661,26 @@ function replies($topic_id, $topic_replies)
return $output;
}
function thumbnailGifsicle($source, $dest_name)
function thumbnailNative($source, $dest_name, $type, $width, $height)
{
$copy_original = false;
$source_filesize = filesize($source);
$image = imagecreatefromgif($source);
$width = imagesx($image);
$height = imagesy($image);
imagedestroy($image);
if ($width > MAX_IMAGE_DIMENSIONS || $height > MAX_IMAGE_DIMENSIONS) {
$percent = MAX_IMAGE_DIMENSIONS / (($width > $height) ? $width : $height);
$new_width = round($width * $percent);
$new_height = round($height * $percent);
shell_exec('gifsicle --no-warnings --colors 256 --resize '.$new_width.'x'.$new_height." \"$source\" > \"thumbs/$dest_name\"");
$dest_filesize = filesize("thumbs/$dest_name");
if ($type == 'gif') {
shell_exec('gifsicle --no-warnings --colors 256 --resize '.$new_width.'x'.$new_height." \"$source\" > \"thumbs/$dest_name\"");
} else {
shell_exec('convert -resize '.$new_width.'x'.$new_height." \"$source\" \"thumbs/$dest_name\"");
}
if (!file_exists("thumbs/$dest_name") || $dest_filesize == 0) {
return thumbnail($source, $dest_name, 'gif', true);
if (!file_exists("thumbs/$dest_name") || $dest_filesize = filesize("thumbs/$dest_name") == 0) {
return thumbnail($source, $dest_name, $type, true);
}
} else {
$new_width = $width;
@@ -1703,27 +1701,28 @@ function thumbnail($source, $dest_name, $type, $force_internal = false)
$type = strtolower($type);
switch ($type) {
case 'jpg':
$image = imagecreatefromjpeg($source);
case 'gif':
$image = imagecreatefromgif($source);
break;
case 'gif':
if (defined('USE_GIFSICLE') && !$force_internal) {
return thumbnailGifsicle($source, $dest_name);
} else {
$image = imagecreatefromgif($source);
}
case 'jpg':
$image = imagecreatefromjpeg($source);
break;
case 'png':
$image = imagecreatefrompng($source);
break;
}
$width = imagesx($image);
$height = imagesy($image);
if (!$force_internal && (($type == 'gif' && USE_GIFSICLE) || ($type != 'gif' && USE_IMAGICK))) {
imagedestroy($image);
return thumbnailNative($source, $dest_name, $type, $width, $height);
}
if ($width > MAX_IMAGE_DIMENSIONS || $height > MAX_IMAGE_DIMENSIONS) {
$percent = MAX_IMAGE_DIMENSIONS / (($width > $height) ? $width : $height);
@@ -1927,17 +1926,17 @@ function matchIgnoredName($ignoredNames, $namefag, $tripfag)
$needMatches = 0;
if ($ignoredNamefag) {
$needMatches++;
++$needMatches;
}
if ($ignoredTripfag) {
$needMatches++;
++$needMatches;
}
if ($ignoredNamefag && $namefag && strcasecmp($ignoredNamefag, $namefag) == 0) {
$needMatches--;
--$needMatches;
}
if ($ignoredTripfag && $tripfag && strcasecmp($ignoredTripfag, $tripfag) == 0) {
$needMatches--;
--$needMatches;
}
if ($needMatches == 0) {
View
@@ -150,7 +150,7 @@
echo 'rounded ';
}
echo 'page-'.preg_replace('%^/|\.php$%i', '', $_SERVER['SCRIPT_NAME']);
echo ' ' . (MOBILE_MODE?'mobile':'desktop').'-mode';
echo ' '.(MOBILE_MODE ? 'mobile' : 'desktop').'-mode';
echo '"';
echo '>';
if ($administrator && false) {
View
@@ -20,7 +20,7 @@
$link->db_exec('show tables');
$tableCount = 0;
while ($link->fetch_row()) {
$tableCount++;
++$tableCount;
}
function doDatabaseUpgrade($old, $new)
View
@@ -769,7 +769,7 @@ function preg_replace_anchors($data)
);
if (!$reply_deleted) {
$undeleted_replies++;
++$undeleted_replies;
}
$last_was_delete = $reply_deleted || $reply_hidden;

0 comments on commit c06ddd3

Please sign in to comment.