-
Posts
4,077 -
Joined
-
Last visited
-
Days Won
87
Everything posted by horst
-
Hi Antti, sorry, I have forgotten to put the JS file into the pull request. (You know, I first have to learn to get rid of that GitHub stuff ) I have opened a new Pull request with the JS file.
-
@Ryan: I have send a pull request for the imageSizer because Roope has found an issue and I have found one some too. Also I have added linearized gamma workflow to get better / brighter results. (more about gamma errors in picture scaling). I have setup a local page for testing the results of different resizes with different options. Also a check if transparency with gif and png is respected. This will be useful with further testing ( Screenshot ) EDIT: @Ryan, meanwhile I have rewritten the ___resize method and it seems to work very well with all kinds of image dimensions: http://nogajski.de/priv/postings/rearrangedImageSizer.html should I commit this to the previous opened pull request? I have three parts put into separate methods: prepareImageLayer writeIPTC getCropDimensions and thats the rewritten ___resize method: /** * Resize the image proportionally to the given width/height * * Note: Some code used in this method is adapted from code found in comments at php.net for the GD functions * * @param int $targetWidth Target width in pixels, or 0 for proportional to height * @param int $targetHeight Target height in pixels, or 0 for proportional to width. Optional-if not specified, 0 is assumed. * @return bool True if the resize was successful * * @todo this method has become too long and needs to be split into smaller dedicated parts * */ public function ___resize($targetWidth, $targetHeight = 0) { $orientations = null; // @horst $needRotation = $this->autoRotation !== true ? false : ($this->checkOrientation($orientations) && (!empty($orientations[0]) || !empty($orientations[1])) ? true : false); $source = $this->filename; $dest = str_replace("." . $this->extension, "_tmp." . $this->extension, $source); $image = null; switch($this->imageType) { // @teppo case IMAGETYPE_GIF: $image = @imagecreatefromgif($source); break; case IMAGETYPE_PNG: $image = @imagecreatefrompng($source); break; case IMAGETYPE_JPEG: $image = @imagecreatefromjpeg($source); break; } if(!$image) return false; if($needRotation) { // @horst (Rotation is executed first because it can change width and height dimensions!) $image = $this->imRotate($image, $orientations[0]); if($orientations[0] == 90 || $orientations[0] == 270) { // we have to swap width & height now! $tmp = array($targetWidth, $targetHeight); $targetWidth = $tmp[1]; $targetHeight = $tmp[0]; $tmp = array($this->getWidth(), $this->getHeight()); $this->setImageInfo($tmp[1], $tmp[0]); } if($orientations[1] > 0) { $image = $this->imFlip($image, ($orientations[1] == 2 ? true : false)); } } // if we need to _scale_ an image we can get better results with first linearize the gamma curve // and convert back later, - after manipulations are finished - // but we cannot use it together with (transparent) PNG $linearizedGamma = false; // get all dimensions at first, before any image operation list($gdWidth, $gdHeight, $targetWidth, $targetHeight) = $this->getResizeDimensions($targetWidth, $targetHeight); $w1 = ($gdWidth / 2) - ($targetWidth / 2); $h1 = ($gdHeight / 2) - ($targetHeight / 2); $this->getCropDimensions($w1, $h1, $gdWidth, $targetWidth, $gdHeight, $targetHeight); // now lets check what operations are necessary: if($gdWidth==$targetWidth && $gdWidth==$this->image['width'] && $gdHeight==$this->image['height'] && $gdHeight==$targetHeight) { // this is the case if the original size is requested or a greater size but upscaling is set to false. // we only need one operation and without resampling, just copy! $thumb = imagecreatetruecolor($gdWidth, $gdHeight); $this->prepareImageLayer($thumb, $image); imagecopy($thumb, $image, 0, 0, 0, 0, $targetWidth, $targetHeight); $this->sharpening = 'none'; // no need for sharpening because we use original copy without scaling } elseif($gdWidth==$targetWidth && $gdHeight==$targetHeight) { // this is the case if we scale up or down without cropping // we need one operation with resampling. if($this->imageType != IMAGETYPE_PNG) { imagegammacorrect($image, 2.0, 1.0); // linearize gamma to 1.0 $linearizedGamma = true; } $thumb = imagecreatetruecolor($gdWidth, $gdHeight); $this->prepareImageLayer($thumb, $image); imagecopyresampled($thumb, $image, 0, 0, 0, 0, $gdWidth, $gdHeight, $this->image['width'], $this->image['height']); } else { // we use two steps if we scale up or down and also need to crop! if($this->imageType != IMAGETYPE_PNG) { imagegammacorrect($image, 2.0, 1.0); // linearize gamma to 1.0 $linearizedGamma = true; } $thumb2 = imagecreatetruecolor($gdWidth, $gdHeight); $this->prepareImageLayer($thumb2, $image); imagecopyresampled($thumb2, $image, 0, 0, 0, 0, $gdWidth, $gdHeight, $this->image['width'], $this->image['height']); $thumb = imagecreatetruecolor($targetWidth, $targetHeight); $this->prepareImageLayer($thumb, $image); imagecopyresampled($thumb, $thumb2, 0, 0, $w1, $h1, $targetWidth, $targetHeight, $targetWidth, $targetHeight); imagedestroy($thumb2); } if($this->sharpening && $this->sharpening != 'none') $thumb = $this->imSharpen($thumb, $this->sharpening); // @horst // write to file $result = false; switch($this->imageType) { case IMAGETYPE_GIF: if($linearizedGamma) { imagegammacorrect($thumb, 1.0, 2.0); // correct gamma from linearized 1.0 back to 2.0 } $result = imagegif($thumb, $dest); break; case IMAGETYPE_PNG: // convert 1-100 (worst-best) scale to 0-9 (best-worst) scale for PNG $quality = round(abs(($this->quality - 100) / 11.111111)); $result = imagepng($thumb, $dest, $quality); break; case IMAGETYPE_JPEG: if($linearizedGamma) { imagegammacorrect($thumb, 1.0, 2.0); // correct gamma from linearized 1.0 back to 2.0 } $result = imagejpeg($thumb, $dest, $this->quality); break; } @imagedestroy($image); @imagedestroy($thumb); if($result === false) { if(is_file($dest)) @unlink($dest); return false; } unlink($source); rename($dest, $source); $this->writeIPTC(); // @horst: if we've retrieved IPTC-Metadata from sourcefile, we write it back now $this->loadImageInfo($this->filename); $this->modified = true; return true; }
-
Hi Mick, i have done the pop3 stuff of the module but I don't know how to do the whole story of your question. But maybe there is help with some kind of dirty hack: The sender is identified as $from and to get it out there and into a pw page you may set it into the $BodyText (like e.g. $BodyText = "<|$from|>\n"). This way you later can extract it from the page body once the page is created. Or you may look into the modules file if there is a way to hook into it somewhere before the page get created. btw: Do you know that there is also another module Process Email to Page. Maybe it supports what you need out of the box. (I don't know it, but there is a real chance it could be)
-
Soma, you no more should use exit for that sort of "rapid debugging"! Maybe you should use the "advanced rapid debug" method like: die("<p style='margin:10px;padding:20px;background-color:sienna;color:white;'>RIP :: now I'm dead, because Soma has shot me here: <br />" . __FILE__ . ' : ' . __LINE__ . '</p>');
-
I have had to rewrite it because the alpha transparency wasn't supported at all. I just have pushed the version 0.0.8 to GitHub. There are some other fixes and changes with the version 0.0.8: added enhanced support for Thumbnails module, including permanent storage for CropRectangleCoords and params fixed / rewritten all bg-color stuff to support rgba alpha channel fixed a E-Notice with IPTC prepare changed the params of method resize, width, height to be the same like in new ImageSizer, ($sharpen can have value 'none') I will also update the first post of this thread.
-
In the above code I have forgotten the channels, so the correct code could be: function getMaxMem() { // read PHP maxMemory from php.ini $sMem = trim(ini_get('memory_limit')); preg_match('/^[0-9].*([k|K|m|M|g|G])$/', $sMem, $match); $char = isset($match[1]) ? $match[1] : ''; switch(strtoupper($char)) { case 'G': $maxMem = intval(str_replace(array('G','g'),'',$sMem)) * 1073741824; break; case 'M': $maxMem = intval(str_replace(array('M','m'),'',$sMem)) * 1048576; break; case 'K': $maxMem = intval(str_replace(array('K','k'),'',$sMem)) * 1024; break; default: $maxMem = intval($sMem); } return $maxMem; } function checkMemoryForImage($imageFilename, $maxMem) { // images pixel $size = getimagesize($imageFilename); $channels = isset($size['channels']) && $size['channels']>0 && $size['channels']<=4 ? $size['channels'] : 3; $imgMem = $size[0] * $size[1] * $channels; // read current allocated memory $curMem = memory_get_usage(true); // memory_get_usage() is always available with PHP since 5.2.1 // check if we have enough RAM to resize the image return ($maxMem - $curMem > 2.5 * $imgMem) ? true : false; } $maxMem = getMaxMem(); foreach($imageFiles as $imageFile) { if(!checkMemoryForImage($imageFile, $maxMem)) { throw new WireException("Cannot load the imagefile {$imageFile->name} into Memory! Imagedimensions are to large."); // or e.g. with modules use $this->error("Cannot load the imagefile {$imageFile->name} into Memory! Imagedimensions are to large.") continue; } // do the resize ... }
-
there is also a short way to write it in PHP. Maybe you know it from JS: $image = $page->images->first(); $img = ($image->width >= $image->height) ? $image->width(900) : $image->height(900); echo "<img src='{$img->url}' alt=''>";
-
OK, I just have deleted my fork complete, and then GitHub has created a new one, like the first time. That new one I was able to modify and send as a PullRequest. So, yes I know, - that's not the recommended way to do it, but I need to go to bed and want it solved before.
- 1 reply
-
- 2
-
oh, it's possible because of the help from owzim! so it should be: "Big tnx @owzim, too"
-
SOLVED! Hi, I want to send a PullRequest to Anttis Thumbnails module, what I already have done one time. GitHub has created a branch patch-1 for that. But that first one has to be modified (a lot), what I have done yet. But when I tried to send a new pull request GitHub denies it and says something that I have allready send one. So,- ?? how can I get the code to Anttis Thumbnails module? PS: https://github.com/horst-n/Thumbnails/compare/apeisa:master...patch-1 Request is send: https://github.com/apeisa/Thumbnails/pull/13
-
The next version of PiM will be able to enhance the Thumbnails module (after I have successful send a pull request to apeisa and he have had time to check and implement the code, - hopefully) While writing on the (optional) support for PiM with Thumbnails, owzim has written the js-code that rebuilds the crop rectangle, - and also he has tested and forthrightly commented my various tests with that. Thumbnails will recognize if PiM is installed and use a different routine then. And without PiM the Thumbnails Module will use the PW core ImageSizer. Since dev-version 2.3.3 the ImageSizer uses automatic sharpening after resize. So - once after updating to the new module and a newer PW version (dev 2.3.3 or stable 2.4) everyone has sharpening support. We both (owzim & me) want to have the coords & data stored and pre-selected when coming back to a previous created thumbnail. We use a wrapper class with a read and a write method on a session basis to achieve that. (After closing the browser or otherwise destroy the session, all data is lost) But together with PiM the coords and options can be stored permanent! It can be stored as metadata in a IPTC custom field (2#215) with the original imagefile. If you want enable permanent storage you have to create a config array named imageManipulatorOptions in your site/config.php and create the key thumbnailCoordsPermanent and set it to true: $config->imageManipulatorOptions = array( // ... 'thumbnailCoordsPermanent' => true ); So, - if you don't want permanent storage, you are still able to use Thumbnails Module and PiM together, but without permanent storage. https://youtu.be/IHwjL7YSfRo EDIT: PullRequest is send https://github.com/apeisa/Thumbnails/pull/13 (the unorthodox way)
-
Ryan, wouldn't it be better to check if the current available memory is enough for a image resize? If we restrict it in the config.php for 32M, all above that (64M, 128M, 256M, ...) have to change the setting. And if they don't know it, they first run into the limitation. I think if we try to find a point for the maximum we have to guess how much RAM PW has allocated before the call to image resize. I don't know how much memory PW allocated for a 'normal' ? request, but lets say it would be something like 14M for example, we have 18M for the image resize. We need memory for the source image and for the target image plus memory for the image operation(s). - lets use a factor 2.5 18 / factor 2.5 = 7.200.000 / 3 (channels RGB) = 2.400.000 (this would be the setting for the config.php)! This could be a image of 1250 x 1920 px. But it will crash if PW has allocated 15M and not 14M. That said, one possible way (without a setting in config.php) could be to check the available memory: function checkMemoryForImage($imageFilename) { // images pixel $size = getimagesize($imageFilename); $imgPix = $size[0] * $size[1]; // read PHP maxMemory from php.ini $sMem = trim(ini_get('memory_limit')); preg_match('/^[0-9].*([k|K|m|M|g|G])$/', $sMem, $match); $char = isset($match[1]) ? $match[1] : ''; switch(strtoupper($char)) { case 'G': $maxMem = intval(str_replace(array('G','g'),'',$sMem)) * 1073741824; break; case 'M': $maxMem = intval(str_replace(array('M','m'),'',$sMem)) * 1048576; break; case 'K': $maxMem = intval(str_replace(array('K','k'),'',$sMem)) * 1024; break; default: $maxMem = intval($sMem); } // read current allocated memory $curMem = memory_get_usage(true); // memory_get_usage() always is available with PHP since 5.2.1 // check if we have enough RAM to resize the image if($maxMem - $curMem > 2.5 * $imgPix) { return true; } return false; } The code is meant as example. There should be only one call per Request (or per Session?) to the php.ini to get the maxMem, and not one call per image resize, etc.
-
Hi Henning, I think you have the wrong param for opacity. PHP.net says: function imagecolorallocatealpha param alpha: A value between 0 and 127. 0 indicates completely opaque while 127 indicates completely transparent. Please try with child->image2->pimLoad('wh', true)->canvas(195, 193, array(0, 0, 0, 127), "centered", 0)->pimSave()->url; EDIT: @Henning: I have noticed that the common way to define a rgba color is 0-255 for R, G and B and a float value between 0 and 1 for the alpha channel (opacity). 0 is transparent and 1 is opaque. I think it is better to use the common way with float 0-1 as param and convert it internally to suite the need of the GD-lib. The change will go into the module version 0.0.8 and I will release it later this weekend.
-
something like this: $im = new ImageSizer($targetPath); $im->resize($targetWidth, $targetHeight); //or $im->width($targetWidth, $options); // $options are optional!
-
As I can see both sides and maybe some more facettes, I like this: taken from here, the answer to question number 5)
-
The classnames are following the nameing conventions, but the descriptions not all. I would like the name Thumbnail in front of all 3 descriptions because it is known as "the Thumbnails module"!
-
It is possible to define a maximum number of allowed pixel (like Megapixel) somehow and it can be checked before loading the imagefile into memory with the getimagesize function: $size = getimagesize($filename); $maxPix = $size[0] * $size[1];
-
<maybe-this-helps>http://processwire.com/talk/topic/4096-how-to-translate-text-containing-html-tags/#entry40116</maybe-this-helps>
-
@Wanze: they have wide support for HTML and CSS: http://processwire.com/talk/topic/4338-how-to-include-mpdf/#entry42512 and also using different fonts is easy. Don't know TCPDF, but have read there docs and can't remember of such wide support for CSS / HTML. ?
-
@Manol: that's a good find. They have wide support for HTML and CSS and also using different fonts is just a snap.
-
@WillyC: thanks for pointing to it. without maybe I could forget the varied features of the forum software (SCNR)
-
Pete, at the "New content" view the button hasn't the pid of the post in the link-href like it has it in all other forum sections. (... §ion=findpost&pid= )
-
Note: when I try use the filter, I don't get PW with: /dir/cms/free/php/ only with: /dir/cms/open-source/php/ There are other open source cms also listed with the free filter, PW not. Why?
-
You can set set_time_limit(30); within the foreach-loop. That way you have higher settings only with that script, not with the whole server. EDIT: If you need for what ever reason a check you can do it at your own: $start = time(); $maxallowed = 600; foreach($somethings as $something) { // ... your code set_time_linit(10); // reset the countdown for every loop! if(time() > ($start + $maxallowed)) { // check the max executed time of the script // break or exit or whatever } }