]> git.mxchange.org Git - friendica.git/commitdiff
photo rotation
authorfriendica <info@friendica.com>
Wed, 23 May 2012 08:01:04 +0000 (01:01 -0700)
committerfriendica <info@friendica.com>
Wed, 23 May 2012 08:01:04 +0000 (01:01 -0700)
include/Photo.php
mod/photos.php
view/photo_edit.tpl
view/theme/duepuntozero/style.css

index 4d02b5c651206359d565598b193057924ba92a74..fce55999961c3f5d377c367eb69ab14a8f40d9f9 100644 (file)
@@ -87,6 +87,12 @@ class Photo {
 
        }
 
+       public function rotate($degrees) {
+               $this->image  = imagerotate($this->image,$degrees,0);
+               $this->width  = imagesx($this->image);
+               $this->height = imagesy($this->image);
+       }       
+
 
 
        public function scaleImageUp($min) {
index 082947bdbfc9c5c5f78ff597b41acffa7ce42afc..3ce6f9934d27f8d4eb2d5d002ecf87a6b276f953 100644 (file)
@@ -287,6 +287,7 @@ function photos_post(&$a) {
 
        if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
 
+
                $desc        = ((x($_POST,'desc'))    ? notags(trim($_POST['desc']))    : '');
                $rawtags     = ((x($_POST,'newtag'))  ? notags(trim($_POST['newtag']))  : '');
                $item_id     = ((x($_POST,'item_id')) ? intval($_POST['item_id'])       : 0);
@@ -300,7 +301,61 @@ function photos_post(&$a) {
 
                if(! strlen($albname))
                        $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
+
+
+               if((x($_POST,'rotate') !== false) && (intval($_POST['rotate']) == 1)) {
+                       logger('rotate');
+
+                       $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
+                               dbesc($resource_id),
+                               intval($page_owner_uid)
+                       );
+                       if(count($r)) {
+                               $ph = new Photo($r[0]['data']);
+                               if($ph->is_valid()) {
+                                       $ph->rotate(270);
+
+                                       $width  = $ph->getWidth();
+                                       $height = $ph->getHeight();
+
+                                       $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
+                                               dbesc($ph->imageString()),
+                                               intval($height),
+                                               intval($width),
+                               dbesc($resource_id),
+                               intval($page_owner_uid)
+                                       );
+
+                                       if($width > 640 || $height > 640) {
+                                               $ph->scaleImage(640);
+                                               $width  = $ph->getWidth();
+                                               $height = $ph->getHeight();
                
+                                               $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1 limit 1",
+                                                       dbesc($ph->imageString()),
+                                                       intval($height),
+                                                       intval($width),
+                               dbesc($resource_id),
+                               intval($page_owner_uid)
+                                               );
+                                       }
+
+                                       if($width > 320 || $height > 320) {
+                                               $ph->scaleImage(320);
+                                               $width  = $ph->getWidth();
+                                               $height = $ph->getHeight();
+
+                                               $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2 limit 1",
+                                                       dbesc($ph->imageString()),
+                                                       intval($height),
+                                                       intval($width),
+                               dbesc($resource_id),
+                               intval($page_owner_uid)
+                                               );
+                                       }       
+                               }
+                       }
+               }
 
                $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
                        dbesc($resource_id),
@@ -1105,7 +1160,7 @@ function photos_content(&$a) {
                $photo = array(
                        'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg',
                        'title'=> t('View Full Size'),
-                       'src'  => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg'
+                       'src'  => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '?f=&_u=' . datetime_convert('','','','ymdhis')
                );
 
                if($nextlink)
@@ -1185,6 +1240,7 @@ function photos_content(&$a) {
                        $edit_tpl = get_markup_template('photo_edit.tpl');
                        $edit = replace_macros($edit_tpl, array(
                                '$id' => $ph[0]['id'],
+                               '$rotate' => t('Rotate CW'),
                                '$album' => template_escape($ph[0]['album']),
                                '$newalbum' => t('New album name'), 
                                '$nickname' => $a->data['user']['nickname'],
index 9950cc4aca5400cfe328cf4b31d0ac3b99306f6c..f6059a7ecc2212f4af76c9c1db9d7f7c09021a98 100644 (file)
        <input name="newtag" id="photo-edit-newtag" size="84" title="$help_tags" type="text" />
 
        <div id="photo-edit-tags-end"></div>
+       <div id="photo-edit-rotate-wrapper">
+               <div id="photo-edit-rotate-label">$rotate</div>
+               <input type="checkbox" name="rotate" value="1" />
+       </div>
+       <div id="photo-edit-rotate-end"></div>
 
        <div id="photo-edit-perms" class="photo-edit-perms" >
                <a href="#photo-edit-perms-select" id="photo-edit-perms-menu" class="button" title="$permissions"/>
index c556dcead4a320f72ec110cf6d86b33d9512b825..fca935dee54e5ad600d679ff8d814faab0f152ae 100644 (file)
@@ -2118,7 +2118,7 @@ aside input[type='text'] {
        margin-bottom: 15px;
 }
 
-#photo-edit-caption-label, #photo-edit-tags-label, #photo-edit-albumname-label {
+#photo-edit-caption-label, #photo-edit-tags-label, #photo-edit-albumname-label, #photo-edit-rotate-label {
        float: left;
        width: 150px;
 }
@@ -2127,7 +2127,7 @@ aside input[type='text'] {
        margin-bottom: 15px;
 }
 
-#photo-edit-caption, #photo-edit-newtag, #photo-edit-albumname {
+#photo-edit-caption, #photo-edit-newtag, #photo-edit-albumname, #photo-edit-rotate {
        float: left;
        margin-bottom: 25px;
 }
@@ -2138,10 +2138,14 @@ aside input[type='text'] {
        margin-bottom: 25px;
 }
 
-#photo-edit-caption-end, #photo-edit-tags-end, #photo-edit-albumname-end {
+#photo-edit-caption-end, #photo-edit-tags-end, #photo-edit-albumname-end, #photo-edit-rotate-end {
        clear: both;
 }
 
+#photo-edit-rotate-end {
+       margin-bottom: 15px;
+}
+
 #photo-edit-delete-button {
        margin-left: 200px;
 }