[chronojump] Image resize to 150 / (maintain aspect ratio)



commit 83960cef9e4a8188592ea7fe7d88931a4475df24
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Feb 2 17:51:03 2018 +0100

    Image resize to 150 / (maintain aspect ratio)

 src/gui/chronojump.cs |    3 ---
 src/gui/person.cs     |    2 +-
 src/utilMultimedia.cs |   14 +++++++++++++-
 3 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index dcf14ef..0db33f5 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -209,9 +209,6 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.VBox vbox_rest_time_set;
        [Widget] Gtk.SpinButton spinbutton_rest_minutes;
        [Widget] Gtk.SpinButton spinbutton_rest_seconds;
-       [Widget] Gtk.Button button_edit_current_person;
-       [Widget] Gtk.Button button_show_all_person_events;
-       [Widget] Gtk.Button button_delete_current_person;
        
        //tests
        //jumps
diff --git a/src/gui/person.cs b/src/gui/person.cs
index 0583b5f..3f939e8 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.cs
@@ -1008,7 +1008,7 @@ public class PersonAddModifyWindow
                        {
                                //mini will be always png from now on (after 1.7.1-213)
                                string filenameMini = Util.GetPhotoPngFileName(true, currentPerson.UniqueID);
-                               bool miniSuccess = UtilMultimedia.LoadAndResizeImage(fc.Filename, 
filenameMini, 150, 150);
+                               bool miniSuccess = UtilMultimedia.LoadAndResizeImage(fc.Filename, 
filenameMini, 150, -1); //-1: maintain aspect ratio
 
                                if(miniSuccess)
                                {
diff --git a/src/utilMultimedia.cs b/src/utilMultimedia.cs
index 2555450..8dd7043 100644
--- a/src/utilMultimedia.cs
+++ b/src/utilMultimedia.cs
@@ -87,7 +87,7 @@ public class UtilMultimedia
                {
                        return false;
                }
-               
+
                bool success = ImageSurfaceResize(imgSurface, filenameDest, width, height);
                return success;
        }
@@ -124,9 +124,21 @@ public class UtilMultimedia
                return imgSurface;
        }
 
+       //height can be -1 to maintain aspect ratio
        public static bool ImageSurfaceResize(ImageSurface imgSurface, string filename_dest,
                        int width, int height)
        {
+               //maintain aspect ratio
+               if(height == -1)
+               {
+                       double ratioOriginal = imgSurface.Width / (1.0 * imgSurface.Height);
+                       height = Convert.ToInt32( width / ratioOriginal);
+               }
+
+               //return if problems on calculating aspect ratio
+               if(width <= 0 || height <= 0)
+                       return false;
+
                Surface surfaceResized = scale_surface(
                                imgSurface, imgSurface.Width, imgSurface.Height, width, height);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]