Put your message here! Contact me for more information
 
 







 

Archive for the ‘Web Scripting’ Category


 


I’ve just made a comments on php.net’s manual page under imagecopyresized() about resizing transparent PNGs with GD. Here is the post again, hopefully it can help someone. Comments are welcome.

Belows is the code snipet that allows you to resize a transparent PNG and composite it into another image. The code is tested to work with PHP5.1.2, GD2, but I think it can also work with other versions of PHP and GD.

The code has been commented to help you read through it. The idea of resizing the transparent PNG image is to create a new destination image which is completely transparent then turn off the imageAlphaBlending of this new image so that when the PNG source file is copied, its alpha channel is still retained.

===Code:===


/**
* Compose a PNG file over a src file.
* If new width/ height are defined, then resize the PNG (and keep all the transparency info)
* Author: Alex Le - http://www.alexle.net
*/
function imageComposeAlpha( &$src, &$ovr, $ovr_x, $ovr_y, $ovr_w = false, $ovr_h = false)
{
if( $ovr_w && $ovr_h )
$ovr = imageResizeAlpha( $ovr, $ovr_w, $ovr_h );

/* Noew compose the 2 images */
imagecopy($src, $ovr, $ovr_x, $ovr_y, 0, 0, imagesx($ovr), imagesy($ovr) );
}

/**
* Resize a PNG file with transparency to given dimensions
* and still retain the alpha channel information
* Author: Alex Le - http://www.alexle.net
*/
function imageResizeAlpha(&$src, $w, $h)
{
/* create a new image with the new width and height */
$temp = imagecreatetruecolor($w, $h);

/* making the new image transparent */
$background = imagecolorallocate($temp, 0, 0, 0);
ImageColorTransparent($temp, $background); // make the new temp image all transparent
imagealphablending($temp, false); // turn off the alpha blending to keep the alpha channel

/* Resize the PNG file */
/* use imagecopyresized to gain some performance but loose some quality */
imagecopyresized($temp, $src, 0, 0, 0, 0, $w, $h, imagesx($src), imagesy($src));
/* use imagecopyresampled if you concern more about the quality */
//imagecopyresampled($temp, $src, 0, 0, 0, 0, $w, $h, imagesx($src), imagesy($src));
return $temp;
}
?>

===Example usage:===


header('Content-type: image/png');

/* Open the photo and the overlay image */
$photoImage = ImageCreateFromJPEG('images/MiuMiu.jpg');
$overlay = ImageCreateFromPNG('images/hair-trans.png');

$percent = 0.8;
$newW = ceil(imagesx($overlay) * $percent);
$newH = ceil(imagesy($overlay) * $percent);

/* Compose the overlay photo over the target image */
imageComposeAlpha( $photoImage, $overlay, 86, 15, $newW, $newH );

/* Open another PNG file, then resize and compose it */
$watermark = imagecreatefrompng('images/watermark.png');
imageComposeAlpha( $photoImage, $watermark, 10, 20, imagesx($watermark)/2, imagesy($watermark)/2 );

/**
* Open the same PNG file then compose without resizing
* As the original $watermark is passed by reference, it was resized already.
* So we have to reopen it.
*/
$watermark = imagecreatefrompng('images/watermark.png');
imageComposeAlpha( $photoImage, $watermark, 80, 350);
Imagepng($photoImage); // output to browser

ImageDestroy($photoImage);
ImageDestroy($overlay);
ImageDestroy($watermark);
?>

view comments
 

Anti 1and1I woke up this morning, found out that my lastproxy site was down, and so are all of my other websites hosted on the same accounts. I was so upset and got on the phone right away to call 1and1.

The lady from 1and1 responded politely about the status of my account, saying that the “admin” had decided to move my account to a different server. I was so mad and angry at the moment, but I tried to keep my temper down. I demanded for an explanation from the 1and1 side - as I haven’t received any advanced notice or emails from them about the usage of my site. The lady put me on hold for about 40 minutes (!) and got back after talking to her supervisor and the “admin” guy, saying that they have had put my account back on, but the “admin” would send me an email afterwards explaining the situation. Fine. An hour after that, I received a somewhat threatening email from them:

Dear Nhat Le, (Customer ID: 91XXXXXX)

Recently we have noticed that your web site(s) is consuming a
disproportionate amount of server resources. Because of this, we have
had to move your account off of the shared hosting server to an
auxilliary server. We now request that you consider purchasing a Managed
or other Dedicated Server in order to continue hosting with 1&1
Internet.

The decision to move your account was made by the system administrators
in order to improve the quality of service for the rest of our clients
on the shared server from which you were previously hosted.
[Why I wasnt’ notified in advanced? You managed to always charge me my money way before I even know about it, so why can’t you let me know in advanced?] The
resources consumed by your account threatened the ability of that server
to capably operate as as a shared host, so it was required that your
account be moved in order to mitigate server load. [By “mitigating”, you mean hacking into my files and disabled it? I will consider to take more actions on this too.]Though we could move
your site back to the original shared hosting server, it is not
recommended. Your account activity has demonstrated that your site
deserves its own server to better suit its performance needs. [Yeah, I’m moving off right now to my own VPS. Thank you!]

Please visit 1and1.com to review the server products we offer. You will
have one (1) month to make a decision and migrate your account over to a
1&1 server or another host provider. [I’m taking action now! And read my lips, I’m not buying anything from 1and1 ever again] You can choose to return your
account back to the shared server, provided that you take steps to
reduce the load generated by your websites. If the account has to be
moved off the shared server system again you will only have the option
of purchasing a dedicated server account to continue hosting with 1&1
Internet.

Please reply to this email promptly. Further questions/comments should
be directed to admin@1and1.com.

Thank you for your compliance in this matter.


Sincerely,
John A. Fernandez
Customer Compliance Operative
1&1 Internet Inc.
Internet.

So they decided to automatically move my site off to a difference server even before notifying me. That’s a pretty stupid and bold move that 1and1 mase. Frankly, I’ve been happy with hosting with them (I’m a 3+ years customer, have recommended 1and1 to friends too). After yesterday when my files got hacked into and today with the closing down of my site, 1and1 just suddenly become a crook now.

I did call them up a week ago asking them SPECIFICALLY about the CPU USAGE POLICY, they told me that anything happened, they would let me know ASAP. I still had the email confirmed my talk with the guy from the support staff. So much for such a promise. You just broke it, 1and1. I really want to file a BBB compliant on 1and1’s reckless business practice. After all this mess has settled down, that’s the action I would take to show 1and1 how to treat customers.

Their advertising scheme is too good to be true: my current business plan got 1Tb transfer - that’s a boat load of bandwidth that a huge, huge (mega) site would take a month. And if your site is that popular, you should be on your own dedicated server already. 1and1 is basically offering the same service for 1/10 of the price of a good dedicated system. The deal is just too good to be true. So the catch is when your site got a little popular, they will FORCE you to upgrade by threatening to close down your site. This is really their business practice. They spend money on flashy, multi-page ads on magazines and at the same time, squeeze hard-earned money on the little webmaster guy who got hooked. 1and1 means they one big bad crook company against one of you.

The only thing that would cause me big trouble is transferring all of my domains to Godaddy. That will be a big pain in the neck as I have about 15 domains hosted on my 1and1 account. What a mess they are causing me. I just wasted my day for all of this non-sense.

My take on this: watch out for 1and1. And don’t sign up with them if you want to do serious hosting. Get a VPS or dedicated instead!

view comments
 

I just found out today that LastProxy.com was hacked. I updated the code last night to optimize for Adsense and things worked beautifully. But this afternoon, I checked on the scripts and found out that both of the proxy scrips stopped working! I FTP to the site and found out that the scripts were removed permissions and hacked by adding ‘exit 0′ at the beginning. To tell the truth, I’m quite shocked.

First of all, I don’t know why anyone would spend time to hack into the scripts. I mean what’s the point of doing so? Secondly, I am very surprised to see someone actually got access to the scripts’ sources. The scripts should always be executed like usual, and how does that person have the permission to write back to the server to add the exit code to both the scripts.

I called 1and1’s support number (contrary to some people, I alwasy get to talk to a live person within 3 minutes and the guys are very, very helpful and nice too). It’s against their policy to change customer’s files. So I know they didn’t go into my site and hacked it. Then someone else got to get in and did it. I checked on the SSH logs and FTP logs, it seems that everything was clean. Very strange indeed.

Well, I’ve wrote 2 posts on Sitepoint forum to see if other people have encoutered something similar. Let’s see what is actually going on. Meanwhile, I’ll be monitoring constantly the site for any sudden changes. And yes, I’ve backed it up, thanks to whoever hacked my site.

view comments
 

After reading my buddy’s blog (http://blog.tvlgiao.com/) about the PHPEclipse, I decided to give it a shot. I’ve been using the Zend IDE because I love the intellisense feature (a.k.a. auto-complete) of this nice IDE. The only thing is that it’s very slow to start and I had a hard time installing the debugger. Well, now the PHPEclipse package also provides the same functionalities with a complete debugger for FREE.

This is the first time I try Eclipse. My impression: impressive! The IDE loads faster than the Zend 5.1.0 IDE, eventhough both run on Java VM. The GUI of Eclipse is also slicker and it gives me the feeling of working in Visual Studio again. Installing the PHPEclipse was a breeze via the Find & Install featured under the Software Update menu. However, installing the php_dbg with Xampp wasn’t that straightforward.

At the time of writing, the php_dbg.dll is only available upto PHP engine version 5.1.2. The newest Xampp is 1.5.4, which bundles the PHP version 5.1.4. I would recommend you to install the older version of Xampp instead. Xampp 1.5.2 is the one with the correct PHP engine to work with php_dbg.

First of all, copy the php_dbg.dll-5.1.2 to the [installed xampp’s dir]/php/ext/. Then add the following lines to the php.ini file. the php.ini file that Xampp’s Apache is using is in the [installed xampp’s dir]/apache/bin/php.ini. You can see the actual path if you do a quick phpinfo().

[debugger]
extension=php_dbg.dll
debugger.enabled = true
debugger.profiler_enabled = true
debugger.JIT_host = clienthost
debugger.JIT_port = 7869

However, the default configuration of the php.ini will crash your Apache because of the loaded ZendExtensionManager.dll. What I did to solve the problem was to comment out the zend_extension_ts lines towards the end of the php.ini file like this…

;zend_extension_ts = "I:\Program Files\xampp\php\zendOptimizer\lib\ZendExtensionManager.dll"
;zend_extension_manager.optimizer_ts = "I:\Program Files\xampp\php\zendOptimizer\lib\Optimizer"
;zend_optimizer.enable_loader = 0
;zend_optimizer.optimization_level=15
;zend_optimizer.license_path =
; Local Variables:
; tab-width: 4
; End:

After all the zend_ lines have been commented out, Apache started just fine and the phpinfo() dump confirmed that the php_dbg has been loaded.

Hope this help. Now it’s time to do some serious php apps with PHPEclipse. Ah by the way, CakePHP with PHPEclips is beautiful! We now have full code auto-complete for the CakePHP’s library! How amazing! And my friend Giao has just told me that Jseclipse for Javascript now support autocomplete for OOP-JS (prototypes and all that good stuff). Ha, it looks like that I’m hooked with Eclipse already.

view comments
 

if($p) {adsense_deluxe_ads(”);}Opening files with different custom extensions in DreamWeaver is pretty annoying: it’ll ask you for the external edit after shouting out the complain. And yes, after you configure Dreamweaver to open the file (through **Edit > Preference > File Type/ Editors**), you only get a plain Code view of the file. **Where the @#$@#$ is the Design View?** And you are working on the next killer template for a site but the template just happens to be of extension ***.thml**. In this case, I’m talking about **CakePHP**. Its default template extension is ***.THTML**. But don’t worry, be happy. Here is the solution to enable DreamWeaver Design View for any custom filetypes, and ***.THML** in particular.

**Now take a deep breath, I know you’ve been waiting for this answer. I know I have.**

- Go to **[Your_Drive_Here]:\Program Files\Macromedia\Dreamweaver MX 2004\Configuration\**
- Open the file **Extensions.txt** and add your custom extensions to the list. Remeber, in **Extensions.txt**, it’s got to be all CAPS. For **CakePhp**, add **THML** to the first line (the one ends with :All Documents) and the **16th** line of the PHP group. Here is the code for the Extensions.txt fileHTM,HTML,SHTM,SHTML,HTA,HTC,XHTML,STM,SSI,JS,AS,ASC,ASR,XML,XSL,XSD,DTD,XSLT,RSS,RDF,LBI,DWT,ASP,ASA,ASPX,ASCX,ASMX,CONFIG,CS,CSS,CFM,CFML,CFC,TLD,TXT,PHP,PHP3,PHP4,PHP5,TPL,LASSO,JSP,JSF,VB,VBS,VTM,VTML,INC,JAVA,EDML,WML,THTML,INC:All Documents
HTM,HTML,HTA,HTC,XHTML:HTML Documents
SHTM,SHTML,STM,SSI,INC:Server-Side Includes
JS:JavaScript Documents
XML,DTD,XSD,XSL,XSLT,RSS,RDF:XML Files
LBI:Library Files
DWT:Template Files
CSS:Style Sheets
ASP,ASA:Active Server Pages
ASPX,ASCX,ASMX,CS,VB,CONFIG:Active Server Plus Pages
CFM,CFML,CFC:ColdFusion Templates
AS:ActionScript Files
ASC:ActionScript Communication Files
ASR:ActionScript Remote Files
TXT:Text Files
PHP,PHP3,PHP4,PHP5,TPL,INC,THTML:PHP Files
LASSO:Lasso Files
JSP,JST:Java Server Pages
JSF:Fireworks Script
TLD:Tag Library Descriptor Files
JAVA:Java Files
WML:WML Files
EDML:EDML Files
VBS:VBScript Files
VTM,VTML:VTML Files
As this first step is just for Dreamweaver to recognize the new file extensions, we have to further edit another config file.
- Go to the **DocumentTypes** folder (still in the same path), edit the file **MMDocumentTypes.xml**\\ (fullpath: [Your_Drive_Here]:\Program Files\Macromedia\Dreamweaver MX 2004\Configuration\**DocumentTypes\MMDocumentTypes.xml**) with a Text Editor (i.e. Notepad or Notepad++). It’s not advisible to edit this particular xml file with Dreamweaver as the software may go crazy as it’s being used to edit itself.
- Go to l**ine 67**, add the THTML extesion to the **winfileextension** and **macfileextensionlist** attributes. Here is the code exerpt

<br /> <MMString:loadString id="mmdocumenttypes_14" /><br />





- Restart DreamWeaver, then open the .thml of CakePHP. Voila! It’s working! Yay! No more blind-coding.

=== Final Remarks ===

I hope you enjoy the tip. To consult the original documentations, please visit [[http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_16410|Dreamweaver Technote: Changing and adding file extensions recognized by Dreamweaver MX]]. if($p)adsense_deluxe_ads(’MediumRectangleLeft’);My final take on this: Dreamweaver is an excellent tool, but the engineers did short of this very important features. Why is it not easier to assign a file extension to be opened with the Design View? Frontpage’s been doing it for years! I don’t know what is the problem with the Dreamweaver team but this is just plain dumb. Sorry, it’s pretty dumb - and it actually managed to be looked over during the user testing. Amazing. But how hard is it to include the new assignment in the GUI? Not that hard at all. -1 for you Dreamweaver!

Anyway, now with the THTML file is through, good luck with CakePHP. Please design the next killer websites to take back the glory for PHP from the RoR crowd.

view comments