Jump to content

horst

PW-Moderators
  • Posts

    4,077
  • Joined

  • Last visited

  • Days Won

    87

Everything posted by horst

  1. Hmm, I have checked how this works with the ImageSizer and have seen that there are more core files invoked (at least Pageimage.php, but maybe also ProcessPageEditImageSelect.module). Initially I have thought with writing an ImageManipulation class it could be the central place for all the images stuff. This way all further improvements on it gets automatically into all modules and templates that work with it. Also I've thought we only need to rewrite the ImageSizer a little bit so that he includes the basics from there too. Hhm, - that's my intial thoughts. But, I don't want go into that depth with (other) core files. I'm only interested in getting sharpened images that keeps their original metadata (IPTC) within all its variations. Therefor I decided to implement AutoRotation, Sharpening and IPTC-Support into the ImageSizer-class, (better: into the resize-method) You should extend in site/config.php the $config->imageSizerOptions Array like: $config->imageSizerOptions = array( 'autoRotation' => true, // true | false 'sharpening' => 'medium', // soft | medium | strong 'upscaling' => true, 'cropping' => true, 'quality' => 90 ); As you know, you set global options there, but you also can set options per/image when calling $img->width, $img->height, or $img->size by passing an options-array as second/third param. The options-array needs only key=>value pairs included with what you want to override the defaultsettings and the global-config-settings. Now it's a bit like an ImageManipulatorLITE You may paste this code into a template and call a page that has at least one viewable image: if($page->images->count()>0) { $size = 240; $options = array( // these are the default settings 'autoRotation' => true, 'sharpening' => 'medium', 'upscaling' => true, 'cropping' => true, 'quality' => 90 ); $quality = array(20,55,90); $sharpen = array('soft','medium','strong'); echo "<p>Quality: 20 - 55 - 90</p>\n"; foreach($quality as $q) echo '<img src="'.$page->images->first->width($size++, array('quality'=>$q))->url.'" alt="" />'; echo "<p>Sharpening: soft - medium - strong</p>\n"; foreach($sharpen as $s) echo '<img src="'.$page->images->first->width($size++, array('sharpening'=>$s))->url.'" alt="" />'; } Here is the modified ImageSizer.php for all of you who want to test it out. If you do so and find some issues / bugs / glitches, it would be nice to post it here. (removed zip attachement because it is obsolete) EDIT: I definitely will finish the ImageManipulation class too. But only in the basic PHP way. Actually i have to put in PW-Errorhandling and to do some testing. ---[technical information]--------------- what was modified added properties: protected $autoRotation protected $sharpening protected $optionNames added methods: public function setAutoRotation($value) public function setSharpening($value) protected function imRotate() protected function imFlip() protected function imSharpen() protected function checkOrientation() protected function iptcPrepareData() protected function iptcMakeTag() modified methods: protected function loadImageInfo() public function setOptions(array $options) public function getOptions() public function __construct() public function ___resize()
  2. Oh, yes it should be. (Haven't realised that) Thanks! Edit: haven't seen at first (because of 'Tunnelblick'): Thank you, Soma!
  3. Hi SiNNut, many thanks for the links. There are interesting things to see like using the GD with layers like Photoshop or Gimp. But the GD-related code is allready done. What isn't achieved now is the PW integration. I would like to have it that we can use it like: $img->open($options)->im_rotate(90)->im_resize(700, 0, true, 'medium')->save(94)->url . Don't know if this is possible and if yes don't know how, so thats a big challenge for me. Actually I can do it in the basic PHP way: $manipulator = new ImageManipulation($filename,$options); $manipulator->im_rotate(90); $manipulator->im_resize(700, 0, true, 'medium'); $manipulator->save(94); Edit / Add: Or with the static OneLiner-Methods you actually can check / correct a imagefile: ImageManipulation::file_jpeg_auto_rotation( $filename, 95 ); This checks the EXIF-Orientation-Flag of an JPEG-Image, corrects it if necessary and save it with quality 94. Is useful for uploaded Images.
  4. Hi, I wish to have a core ImageManipulationClass like the ImageSizer but not only for resizing and cropping images. It should provide these easy to use functionality like with the ImageSizer and additionally a step to step image manipulation whereas the user / module author is not restricted anyhow. The basic image manipulation methods should be included, like: im_flip im_rotate im_crop im_crop_auto im_resize im_sharpen im_stepResize If someone want to do something more fancy or magic, he/she should not to have to reenvent the basics again. He/She just should start with the class by opening the imagefile and create a GD-object, use some basic methods, and at any point get the GD-IM-Reference out, do his fancy magic with it and put it back to the class to use its basics to finalise the file: im_get_im() im_set_im( &$im ) I have started to write something for this. I tried to be as close to the ImageSizer as possible, but some differences will be there. Before I've started with it I have done some tests with sharpening, rotating and others. First I've tried to create a module that hooks into ImageSizer, but have figured out that this wouldn't solve most things what I imagine one want to do with images. I have read the code of ImageSizer very carefully and there are allready very good inprovements in it from the community here. Ok, Ryan has written it and done the most work of all, so tribute to him , - adamkiss, interrobang, mrx, teppo, u-nikos have contributed the improvements to it: . I have looked into apeisas Thumbnail-Module and tried adding functionality for sharpening to it. It think he would have liked if there was a CoreImageManipulation class once when he has written the module. Also Soma actually work on a very cool Module where I really would like to see a link/button or some links/buttons for every image that just let you do some manipulations/corrections to them. <hint, hint ;-)> Any thoughts or Meinungen are welcome. --- EDIT: there is actually a modified ImageSizer class with autoRotation & sharpening available for testing: http://processwire.com/talk/topic/3278-core-imagemanipulation/#entry32284 --- Here are an overview of what allready is in, (I post only properties and method names, not the method bodies): class ImageManipulation extends Wire { // information of source imagefile /** * Filename ImageSourcefile */ protected $filename; /** * Extension ImageSourcefile */ protected $extension; /** * Type of image ( 1 = gif | 2 = jpg | 3 = png ) */ protected $imagetype; /** * Information about the image (width/height) and more */ protected $image = array(); /** * Was the given image modified? */ protected $modified = false; // default options for manipulations /** * Image quality setting, 1..100 */ protected $quality = 90; /** * Allow images to be upscaled / enlarged? */ protected $upscaling = true; /** * Allow images to be cropped to achieve necessary dimension? If so, what direction? * * Possible values: northwest, north, northeast, west, center, east, southwest, south, southeast * or TRUE to crop to center, or FALSE to disable cropping. * Default is: TRUE */ protected $cropping = true; /** * Should a optional Auto-Rotation be performed if EXIF-Orientation-Flag is available? */ protected $auto_orientation = true; /** * the default sharpening mode * * @var array with custom pattern or a string: 'soft' | 'medium' | 'strong' | 'multistep' */ protected $sharpening = 'medium'; /** * if extended imageinfo should be retrieved: number of Channels, Bits/per Channel, Colorspace */ protected $extended_imageinfo = false; /** * Extension / Format for resulting Imagefile (default is same as ImageSourcefile-Extension) */ protected $outputformat; /** * Filename ImageTargetfile if $outputformat is different than InputImage (default is same as ImageSourcefile) */ protected $targetfilename; // other properties /** * Directions that cropping may gravitate towards * * Beyond those included below, TRUE represents center and FALSE represents no cropping. */ static protected $croppingValues = array(); /** * Supported image types (@teppo) */ protected $supportedImageTypes = array(); protected $option_names = array(); private $property_names; // Methods to set and get Properties /** * Here you can specify multiple options as Array, whereas with the * single set* functions you can specify single options * * @param array $options May contain key-value pairs for any valid Options-Propertyname * @return this */ public function setOptions(array $options) public function setQuality($value) public function setUpscaling($value) public function setCropping($value) public function setAuto_orientation($value) public function setSharpening($value) public function setTargetFilename($value) public function setOutputformat($value) /** * Return an array of the current options */ public function getOptions() /** * makes protected and private class-properties accessible in ReadOnly mode * * example: $x = $class->propertyname; */ public function __get( $property_name ) // Construct & Destruct the ImageManipulator for a single image public function __construct( $filename, $options=array() ) public function __destruct() public function im_release() // read image informations, basic and extended protected function loadImageInfo() private function extendedInfo_gif(&$a) private function extendedInfo_jpg(&$a) private function extendedInfo_png(&$a) // helper functions /** * check file exists and read / write access * * @param string $filename * @param boolean $readonly * @return boolean */ private function check_diskfile( $filename, $readonly=false ) /** * helper, reads a 4-byte integer from file */ private function freadint(&$f) // the IM's (ImageManipulation Methods) private $im_dib_dst = null; // is the output for every intermediate im-method and optional a check-out for the im! private $im_dib_tmp = array(); // holds all intermediate im references private function get_next_im( $w=true, $h=null ) public static function is_resource_gd( &$var ) public function im_get_im() public function im_set_im( &$im ) public function im_flip( $vertical=false ) public function im_rotate( $degree, $background_color=0 ) public function im_crop( $pos_x, $pos_y, $width, $height ) public function im_crop_auto( $direction, $width, $height ) public function im_resize( $dst_width=0, $dst_height=0, $auto_sharpen=true, $sharpen_mode='medium' ) public function im_sharpen( $mode='medium' ) public function im_stepResize( $dst_width=0, $dst_height=0 ) // static oneLiner Methods that can be called only with a filename passed to them public static function file_get_exif_orientation( $filename, $return_correctionArray=false ) public static function file_jpeg_auto_rotation( $filename, $quality=95 ) }
  5. Ah, ok. Thanks for the link. I've read the example on php docs and yes they use create_function instead of a 'closure' for the same purpose. Thanks too! WP uses a named function within their preg_replace_callback. So this shouldn't be too complicated to achieve. (Will try when there is more time)
  6. Yes, its the so called closure within the preg_replace_callback. Maybe there also could be used a named function as callback, somehow? But I don't really understand what's going on at that point. Edit / Add: Links about PHP closures with versions prior to 5.3: http://stackoverflow.com/questions/2209327/is-it-possible-to-simulate-closures-in-php-5-2-x-not-using-globals http://www.phpclasses.org/package/5484-PHP-Create-closure-functions-for-any-PHP-5-version.html
  7. Hey Nico, really useful module! Very powerful. I've tried out locally (with PHP 5.3), like it very much, but when uploading to the online host it also crashes the Adminpage. When looking to the code, there is only one closure within the preg_replace_callback what relies on PHP 5.3. Is there any chance to change that to a (surely less elegant) code but that also run with PHP 5.2 ? (Bitte, bitte!) Unfortunately I'm not comfortable with preg_replace & co.
  8. Original, just downsized => why ? or how ? directly with the camera ? Anyway, it's like I've expected: original image and "rotated"-MS-Viewer image are identical = checked with crc32 and md5, (hmm, why do I check with both? ) They are right-top oriented as was to read in Exif-Orientation. (the Viewer do not alter the files, it works as expected from a viewer!) The other one was TopLeft oriented, because your software has corrected it. The other stuff you are showing doesn't make any sense in the behave of PW / GD2. When uploading the same image again and again it couldn't differ. Please check the files in your assets/files/--folders. With all files that need to be rotated one have to wait until the mods have find their way into PW somehow. Sorry for the delay. --- Edit/Add: Ronnie, you should go to a fresh clean empty folder in your Windows System. Leave all other files behind. Then take only one picture from the camera, like you have send with the Zip. Make a copy of it, compare / note filesize and last-modified time of the copy. Put the copy into the MS-Viewer. Rotate it somehow and if your done - go to explorer and compare filesize and last_modified_time again. You may also check if there are options with the Viewer what lets you disable the autocorrected display. You may also use an alternative ImageViewer like Irfan-View. Irfan-View has in its Options under JPG / PCD / GIF > JPEG - Load a CheckBox with: Auto-rotate image according to EXIF-info (if available). I have this unchecked. Also I use Irfan-View as the defaultViewer with Windows 7 x64. It's much faster and more comfortable than any WindowsViewer. I have disabled every correction like using ICC-profiles, rotation, etc. It just throws the images to the screen as is, (looks ugly when its a CMYK.) If your camera supports these different settings, try one by one, carefully. I think at least you come up with two versions: 1 with correction and 1 without. Check both of them and compare, best with an ImageViewer that has disabled auto-corrections. After that go to PW, create a new page and upload these two images. Upload them twice and compare. If you have differences with the same images, I give up.
  9. Hi cmscritic, I just want to note that you now have the <h1>-Tag filled with an image, and only with an image. Hhm, dunno if this is a good idea with respect to SEO and page semantic. (But my profession are the images, not SEO or semantic, just doesn't feel good to me)
  10. - If an image is shoot with a camera so that the Top becomes the right side, (it is rotated 90 degrees clockwise), this is stored in the EXIF-Orientation-Flag. - If a software rotates this image 90 degrees counterclockwise and do not setup the EXIF-Orientation-Flag this is bad for every following software that relies on the EXIF-Oriantation-Flag, but GD2 doesn't do that. My question: does the MS-Photo Viewer really changes the orientation / rotation of an image ? or does it only show them rotated but doesn't alter the files? Can you make three copies of an image and let the first original from camera, the second rotated with MS-Photo-Viewer and the third saved with XnView and send it to me (ZIP 2 PM or upload here)?
  11. functional Link is: https://github.com/adamspruijt/metrowire He has updated it in the Thread (only there).
  12. @arjen: Oh, seems you better understood what is going on with the images. I only have read orientation == rotation. @Ronnie: if your images are not rotated (top is not shown at top), you can ignore my post. Sorry, haven't got it right. My rule for the next few weeks: If want to help, first read carefully the question, second read more carefully the question and third only do answer after understanding it right.
  13. Hi Ronnie and welcome! This sounds that the images you try to upload are originally have a rotation when created. Currently PW doesn't check/recognize the EXIF-orientation-flag in the Core-ImageSizer. But we have already included an autocorrection in the Email-Image-Module, so the code for that is already there (amongst with code for sharpening after downsizing!). But it has to get included into the core somehow. I've started to prepare code with that to send it Ryan so that he can test it, optionally modifiy it and finally add it to the core. But I#m short of time at the moment and can't say when it is done. I bet you localy use an imageviewer that autocorrects the rotation when displaying the images. As a workaround you may try opening an image in a image-app like photoshop, do something like brightness +1% and then -1% and save it. Photoshop autocorrects the rotation when opening the image and also resets the EXIF-orientation-flag when saving the image. This also should work with most other image-manipulation-apps. Edit: The planned additions should be usable also for the Thumbnail-Module. Here are a short screencast about manually sharpening.
  14. Hi, why not using it like: <?php $image = $page->logo_image->size(287,80);?> <?php echo "<a href='{$config->urls->root}'><h1><img class='logo' src='{$image->url}' alt='{$image->description}' /><br />{$homepage->headline}</h1></a>"; ?>
  15. Hi and welcome! <title> <? if($page->alt_title) { echo $page->alt_title; } else { echo $page->title; }; ?> </title> I like the short version of this: <title><?php echo $page->get('alt_title|title');?></title> You may let PW do the work for you
  16. http://wiki.processwire.com needs one too !
  17. Hi Ryan, Using the default AdminTheme with english language displays an ErrorMessage at the Top of the page: Duplicate entry '1002' for key 'data' Using the default AdminTheme with the german language pack do display nothing! Using the Metro AdminTheme with the german language pack do display nothing!Using the Metro AdminTheme with english language do display nothing, too!Other Warnings/Errors, like 'Missing required value ...', 'Value is out of bounds ...' are always displayed as expected. There are no entries in the Error-Logfile with this.
  18. Hi, I have the need to set a field to unique as described here (point 2.) It is a integer input within a repeater. I have set that field to match a minimum and maximum value and also input is required! When trying to save the page with an already used value the page doesn't save that field and do not output any error or warning. It silently lost the data, even with debugging enabled in config.php. What can I do to avoid this?
  19. see this post and the following 5-6 for some pros and cons you shouldn't hesitate, have a look to some of the old foxes and younger (but also well known) foxes around here.
  20. Hi Radek, cool. Edit: It would be really good to have the description-field for images also in multilingual version. Oh, I haven't got it right. It is localization support, - what I have thought of is multilingual inputfields like 'TextLanguage, TextareaLanguage and PageTitleLanguage'. An Image-description-field for that would be really cool.
  21. When using $ as a char within doublequotes in PHP, (and not to indicating a Variable), it should be escaped with a \ (backslash). When using a $ as char within singlequotes, escaping is not necessary. That is because PHP treats strings in singlequotes 'as is' (no further processing is done on it), whereas strings in doublequotes will be parsed and every found variable get replaced by it's value. So, the above example will work in PHP, but will not provide correct code to work with the javascript in your page! The problem with Diogos example is that it breaks the onClick value. To avoid this you have to use escaped doublequotes for the onclick value and within that value singlequotes (for the string that get passed to the javascript function): echo "<li><a href='#{$child->name}' onClick=\"$.scrollTo( '#{$child->name}', 800 );\">{$child->title}</a></li>";
  22. Hi Diogo, I don't have Chrome installed With Firefox I have tested it on the site http://pasteboard.co/ There it works. Would be cool if other Browsers could be supported too.
  23. Hi MarcC, <irony>does you receive the plain-text or the HTML-formatted ?</irony> He has 'overworked' and renewed the design just some years ago (3-4 ?). Do you know the previous one, too?
  24. Hi LeiHa, thanks for sharing this. Also if you say this is your planning code it looks to me to be a real good starting point and I have bookmarked this Post!
×
×
  • Create New...