Page 1 of 1

Positioned croped images in CP "images <div>"

Posted: Fri 30. Nov 2007, 06:04
by metti
Hi out there!

Today i found out, that since release "snapshot 2007-10-12" (1.3.5) it's possible to crop images in the Contentpart "images <div>".

I was really happy about that (Thanx Oli) but missed a feature, that would make this functionality a bit more fiting for me:
To tell phpwcms how much of the image should be croped

So i looked up the code, made some changes and got it to work:

After changing 3 things in 2 files of the core it is possible to use this RP-Tag in the caption of each image:

{POS:x:y}
(x and y are the pixels that are croped on the image and also may be "center")

In the Frontend it looks like this:
http://www.netzelf.de/index.php?aid=3&pg=3

In the Backend it looks like this:
Image

So what is to do to get this working?

Open include/inc_lib/imagick.convert.inc.php and find:

Code: Select all

$default = array(
              		"max_width"		=>	$GLOBALS['phpwcms']["img_list_width"],
              		"max_height"	=>	$GLOBALS['phpwcms']["img_list_height"],
              		"image_dir"		=>	PHPWCMS_ROOT . '/' . PHPWCMS_FILES,
              		"thumb_dir"		=>	PHPWCMS_ROOT . '/' . PHPWCMS_IMAGES,
              		'jpg_quality'	=>	$GLOBALS['phpwcms']['jpg_quality'],
              		'sharpen_level'	=>	$GLOBALS['phpwcms']['sharpen_level'],
              		'crop_image'	=>	false
After this (after line 257) add the following:

Code: Select all

                      ,
              		'crop_x'  => false, //Added for positioned croping
              		'crop_y'  => false  //Added for positioned croping
Then find

Code: Select all

        $crop_x = abs( $image->get_w() - $imagick["max_width"] );
				$crop_x = ceil( $crop_x / 2 );
				$crop_y = abs( $image->get_h() - $imagick["max_height"] );
				$crop_y = ceil( $crop_y / 2 );
and add after this (line 209):

Code: Select all

			  //Added for positioned croping
        if ($imagick['crop_x'] != false && $imagick['crop_y'] != false) {
          $crop_x = ($imagick['crop_x'] != "center") ? $imagick['crop_x'] : $crop_x;
          $crop_y = ($imagick['crop_y'] != "center") ? $imagick['crop_y'] : $crop_y;
        }
        //End of Changes for positioned croping
Open include/inc_front/content/cnt29.article.inc.php and replace

Code: Select all

        $thumb_image = get_cached_image(
						array(	"target_ext"	=>	$image['images'][$key][3],
								"image_name"	=>	$image['images'][$key][2] . '.' . $image['images'][$key][3],
								"max_width"		=>	$image['images'][$key][4],
								"max_height"	=>	$image['images'][$key][5],
								"thumb_name"	=>	md5(	$image['images'][$key][2].$image['images'][$key][4].
															$image['images'][$key][5].$phpwcms["sharpen_level"].
															$image['crop']
														),
								'crop_image'	=>	$image['crop']
        					  )
						);
(line 127 to line 138) with

Code: Select all

			 //Add position for croping images (by netzelf)
      $img_thumb_vars = array(	"target_ext"	=>	$image['images'][$key][3],
								"image_name"	=>	$image['images'][$key][2] . '.' . $image['images'][$key][3],
								"max_width"		=>	$image['images'][$key][4],
								"max_height"	=>	$image['images'][$key][5],
								"thumb_name"	=>	md5(	$image['images'][$key][2].$image['images'][$key][4].
															$image['images'][$key][5].$phpwcms["sharpen_level"].
															$image['crop']
														),
								'crop_image'	=>	$image['crop']  );
      preg_match('/\{POS:(.+?):(.+?)\}/is', $image['images'][$key][6], $img_pos);
      $image['images'][$key][6] = preg_replace('/\{POS:(.+?):(.+?)\}/is', "", $image['images'][$key][6]);
      if (!empty($img_pos[1]) && !empty($img_pos[2])) { 
        $img_thumb_vars["crop_x"] = $img_pos[1];
        $img_thumb_vars["crop_y"] = $img_pos[2];
        $img_thumb_vars["thumb_name"] = md5(	$image['images'][$key][2].$image['images'][$key][4].
															$image['images'][$key][5].$phpwcms["sharpen_level"].
															$image['crop'].$img_pos[1].$img_pos[2]
														);
      }   
      
			$thumb_image = get_cached_image($img_thumb_vars);
      //End of changes for positioned croping
Ready

Hope you will like this as much as me :D

very nice

Posted: Sun 2. Dec 2007, 04:23
by jsw_nz
such an approach has crossed my mind
-so kudo's to you

excellent contribution - extends the concept
i am sure OliG will respond to this

big thanks metti
:)

one question however
does this (exclusively) require imagick to work ?

Posted: Sun 2. Dec 2007, 16:20
by metti
you're welcome :)

no. it works fine with GD. I did not test, if it also works with imagemagick but normaly it should.

Posted: Mon 3. Dec 2007, 00:17
by jsw_nz
Just incorporated your code adjustments
WORKS like a charm - nice! :)

Posted: Mon 3. Dec 2007, 00:42
by metti
:) Nice, that it suits you.

There is one feature this hack is in my oppinion missing:

At the moment OliG's Script always sizes the image to the value you specified for "max. width" in the Backend even if you chose cropping.

I think, that it would be also usefull to make sizing of the image users choice. So i will develop the tag to something like
{POS:crop_x:crop_y:width_x:width_y}
as soon as my freetime allows.

Posted: Tue 18. Dec 2007, 07:14
by jsw_nz
- Not to add to the confusion
- but seeing that OliG has released a new CP: special images
- the thought crossed my mind of how your approach could
- benefit this new additional CP: (still in development)
- http://www.phpwcms.de/forum/viewtopic.php?t=16233

great work metti

Image

Posted: Tue 18. Dec 2007, 23:40
by metti
Thanx jsw_nz!
This was new for me but sounds great.

Would be realy fine, if the crop-thing was integrated to this CP.

Re: Positioned croped images in CP "images <div>"

Posted: Tue 25. May 2010, 22:44
by Jensensen
Hi metti,

Du netzcrack, bist Du eigentlich "halb und halb"?
Äh, was ich eigentlich sagen wollte: --> Kumma da: http://forum.phpwcms.org/viewtopic.php?f=16&t=20177

Re: Positioned croped images in CP "images <div>"

Posted: Sun 30. May 2010, 00:31
by jsw_nz
Thanks Jens for trying
- seems you had mixed results

- i looked over the newest version of imagick.convert.inc
- seeing it has changed a bit.

Still would be a nice feature if Oliver could incorporate into the core
- might make a feature request.

cheers
:D

UPDATE: submitted as a feature request.

Re: Positioned croped images in CP "images <div>"

Posted: Sun 30. May 2010, 01:33
by metti
@jensensen - sorry, what?

Hi,

You are right: cropping images with gd2 is not possible. Well there is no special command for it. But what about taking an empty image with the dimensions to that the original image should get cropped and copying the latter into the empty image? What happens, is that the image will be cropped. That's as far as i remember the way Olivers script and my modifications did it.

I did not use phpwcms since 1.3.9 - so it's perhaps better to contact Oliver for support as he is the developer - is he still the only one?

Cheers,
metti

Re: Positioned croped images in CP "images <div>"

Posted: Tue 11. Sep 2012, 20:17
by NavegarEhPreciso
Hi
The hacker described above at 'Positioned croped images in CP "images <div>"'
Was working fine before version 1.5.4.1.
At this version 1.5.4.1 was not possible made the changes, because the file include/inc_lib/imagick.convert.inc.php it's now different .
Are there some other functionality that replaces that hacker?
I need crop the thumbnails, some at top of the image, others at the bottom.
Regards

Re: Positioned croped images in CP "images <div>"

Posted: Wed 12. Sep 2012, 14:57
by Oliver Georgi
autocropping still uses the centered method. Might be possible to implement something to handle manual attributes. But have no clue right now before having a built-in cropping tool