phpThumb is not setting parameter – fltr[] usm - thumbnails

I am using Brett's Mr. PHP thumb caching script along with phpThumb to create my thumbs. It works extremely well, except for one thing... I cannot get it to set and process the UnSharpMask filter. The relevant part of the script looks like this:
// generate the thumbnail
require('../phpthumb/phpthumb.class.php');
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename($image);
$phpThumb->setParameter('w',$width);
$phpThumb->setParameter('h',$height);
$phpThumb->setParameter('q','95'); // set the quality to 95%
$phpThumb->setParameter('fltr[]','usm|80|0.5|3'); // <--- THIS SHOULD SET THE USM FILTER
$phpThumb->setParameter('f',substr($thumb,-3,3)); // set the output file format
if (!$phpThumb->GenerateThumbnail()) {
error('cannot generate thumbnail');
}
I'm guessing there's a problem with my syntax, since the fltr[] parameter requires brackets. I have tried escaping the brackets like so: 'fltr[]' but that didn't work either.
I've used several other possible parameters with good success (zoom cropping, max height, max width, etc...) Everything seems to work except the filters (including usm - UnSharpMask).
I don't get any errors. It spits out thumbs all day long. They're just not sharpened.
For reference, here's the official phpThumb readme file that discusses all the possible settings and filters.
Thanks for looking.

Well after much trial, error, and aggravation, I finally discovered the solution buried in one of the demo files that come with phpThumb.
It's a matter of removing the brackets all together. Basically changing this line:
$phpThumb->setParameter('fltr[]','usm|80|0.5|3');
to this:
$phpThumb->setParameter('fltr','usm|80|0.5|3');
After that, it's only a matter of tweaking the settings to get the desired amount of sharpness.

Related

TTeeGrid is not displaying the data at runtime using data from REST

I created a simple RME for TTeeGrid, a descendant perhaps of TGrid in Firemonkey. As shown below, the data are displayed at design time but not at runtime except the headers.
I've been breaking my head over this for weeks already but not luck.
Let me know if you need more details but what you see in the image are all you get.
I just need help to have the data displayed at runtime as shown in the design time.
UPDATE 1
This issue is not the case with TPrototypeBindSource. The data shown in the design time are displayed at runtime. Something is wrong somewhere.
I've never used the TeeGrid before, but the following worked fine
first time for me in Delphi Tokyo:
Download the TeeGrid trial from Steema.Com & install.
Create new multi-device app and place a TeeGrid and a FDMemTable on the form.
Load FDMemTable1 with the file Parts.Fds from the Delphi samples Data directory. Note, I did not then create any FieldDefs as I mentioned in my comment earlier as what I'm describing works without them.
Set the DataSource property of TeeGrid1 to FDMemTable1. TeeGrid1 immediately
creates columns for each of the Parts fields and populates them with data - see
screenshot below. I don't ordinarily include screenshots but in this case thought
I would as what I got was so clearly at odds with what you've reported.
Your TeeGrid etc are obviously more complicated than mine. so the best I can
suggest is that you backtrack to step 2 and see if you can replicate my result
with your data (either at design time or run time). It might be worth loading
your FDMemTable with some data at design time, as my impression is that live bindings
is less grief-prone when the datasource has some data.
Incidentally, fwiw the results of my own attempts to set up live bindings even with a regular TGrid have been rather patchy, until I discovered that instead of messing with the LB components myself, simply starting with a fresh TGrid, right-clicking on it and leaving the Live Bindings Wizard
to do its stuff consistently works fine.

Emmet abbreviation for Pug "input" is inserting an unneeded #

I'm working on a Pug template in VS Code and whenever I try to use the emmet abbreviation input:text (or any input for that matter), it resolves to input#(type="text", name="").
It's not the end of the world, but it's driving me crazy, and I can't figure out why it's doing so or how to change it.
I guess my question is: is there any way to change this behavior or any place that I can draw attention to this?
The problem is the treatment of the attributes id and class for indent-based syntaxes (Slim, Pug, etc.).
For some reason it removes the attribute from its current position and pushes to the front the strings # for id and . for class.
This is controlled with 2 regex statements near line 3297 in
C:\Program Files\Microsoft.VS.Code\resources\app\extensions\emmet\node_modules\vscode-emmet-helper\out\expand\expand-full.js
Change
const reId = /^id$/i;
const reClass = /^class$/i;
to
const reId = /^Xid$/i;
const reClass = /^Xclass$/i;
You must also remove the cached version of this file in the directory
C:\Users\__username__\AppData\Roaming\Code\CachedData\__some_hex_value__
Restart VSC and it should work.
For linux systems you have to find the location of these files.
I finally understand why this is happening, and that my confusion was basically a misunderstanding of proper form creation.
All text inputs should have an id associated with them, so Emmet is expecting an ID in the shorthand. So this:
input:text#user
resolves to
input#user(type="text", name="")
Which works great! Too bad it took me months of confusion to I realized how daft I am!

How to debug long scripts in Chrome?

I have a page which has a script tag. The script inside that tag is very long, but I would like to debug it. Unfortunately, I cannot scroll to the relevant place in the Console, because after a certain length the script is simply not displayed, see the attachment:
As you can see, it ends with
return !filt...
The actual function looks like this:
this.validate = function(filters) {
for (var filter in filters) {
if (!innerValidation(filters[filter].filterType, filters[filter].evaluatedValue, data[filters[filter].key])) {
return filters[filter].isOr;
}
}
return !filters[filter].isOr;
};
Question: Why does Chrome truncate my script and how could that be changed?
Note, that I know I could load it from an external file, but I am actually interested to know the cause of this behavior.
The display of the script is truncated but it still parses and runs the code correctly. You should be able to view the full code in the Sources tab under the relevant host and put breakpoints in there.
If you have a long script, it is best to make that into its own file instead. This will provide you with the best debugging experience.
The Elements panel truncates large scripts to help keep things fast and there is no way to undo this. Therefore, you would need to use some external debugging tools to try and get at this, but even then most of them work best with external script files as well.
Inline scripts should be very short if ever used. For any decent sized chunks of scripting, allocate that into its own file.

How can I make a perl script that will rename files in a specific directory every couple minutes?

I wanted to add a live picture rotation to my site and i could not find any other way to do it so i decided that i need a cgi script that will:
1. Delete the first picture in the rotation (e.g. pic1.jpg)
2. Rename the rest of the pictures (e.g. rename pic2.jpg to pic1.jpg, pic3.jpg to pic2.jpg, pic4.jpg to pic3.jpg, etc...)
3. Do this every 5 minutes so that the viewers of my site will all be viewing the same picture pretty much at the sime time.
Any help will be much appreciated,
Thanks.
To make this work "so that the viewers of my site will all be viewing the same picture pretty much at the same time", you need to use different urls for each image or make sure you are telling browsers and proxies not to cache the pictures...and not caching is a really bad idea; your viewers will not appreciate it, nor will your server.
Sounds like a pretty bad idea, frankly. File operations are relatively slow, and tends to step on itself in a highly-concurrent application like a webapp.
Look for another way. How about using the current time as a key to choose among pictures?
currentImageIndex = currentTimeRoundedToTheNearestFiveMinutes %
totalNumberOfImages
Edited with more detail on request:
Basically, take the current time, and round it to the nearest five minutes. Doing something like currentHour / 12, using integer math, will give you this; otherwise, truncate the result. Then use the modulo operator (% in Perl, and many languages - handy operator that newcomers tend to overlook) to produce a number from 0 to n-1, where n is the total number of images you're serving. Then you can refer to a mapping table to go from that index to a filename.
Since you say in a comment that you don't need caching, rather than change the filenames of each file, why not have your page point to a file which is a symlink and then change the pointer of the symlink every few minutes. Seems like it would do what you need without the overhead of major file operations.

Query with toLocalizedTime in Plone

I'm using toLocalizedTime to output a date, as below
<span tal:content="python:here.toLocalisedTime(date.get('start_date'))"/>
This outputs eg. 2007/08/02, I'm just curious as to how one would alter the output so that it reads 02/08/2007
I'm not having much luck finding much info on toLocalizedTime, would someone point me in the right direction?
This depends on whether you have English selected as the site language (Site Setup >> Language). If so, then the default settings are used. You can change the defaults by dropping down into the ZMI, then into 'portal_properties', then 'site_properties'. The fields to change are either 'localTimeFormat' or 'localLongTimeFormat' depending on whether you pass in 'long_format=1' to the toLocalisedTime function.
If on the other hand, you have translations set up, the format may instead be pulled from the translation file for the locale selected. I'm not sure what is the easy way to change the format in this case (other than switching the site back to English). I guess you can register your own translation file but I've never needed to do that so you're going to have to look up the details.
Date string formatting follows the Python rules (http://docs.python.org/library/time.html#time.strftime).
Perhaps even more detail than you need:
here.toLocalizedTime()
is defined in the plone browser view at...
CMFPlone/browser/ploneview.py
which looks up the 'translation_service' utility, to call its 'ulocalized_time' function, defined at...
CMFPlone/TranslationServiceTool.py
which itself calls the 'ulocalized_time' function defined at...
CMFPlone/i18nl10n.py
As always, you can learn interesting things by grepping the source code ;-)
For an up to date answer for Plone 4.3 (after going through the source code)
These fields are now in the registry found at:
http://localhost:8080/yoursite/portal_registry
Then filter on "i18nl10n", which should give you the 4 fields you need to change.