手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:php

关于Imagick的使用

ImagIck这个控件应该算是最近两年来,各个WEB程序员都比较推荐的一个编辑图片的软件。
其实这也是一个分支吧?如果我没有记错,都是从XXX(忘了是哪个了)分出来的,一个是MagickWand,另一个就是这个Imagick了,只是MagicWand好象比较难以控制,并不如这个Imagick方便,再加上Imagick的类及使用方法也集成在PHP手册里了。

本来我是安装了ImageMagick-6.2.5-4-Q16-windows-dll.exe的,然而,愿望总是美好的,结果在Apache下运行的时候,总是提示挂接不上某个动态链接库,装回5.5.7后一切正常,但却无法使用PHP手册里所提供的函数。

本来都想放弃了,可是同事在单位里的Linux上装上了这个软件,但由于我们的PHP版本太低,在大多数的情况下都是直接使用命令行进行操作的。

为了适应将来的PHP版本升级,所以不得不学习这个软件,在我以前的贴子里,也贴过了Imagick官网和一些例子的实现网站。
今后我也会重新拾起代码,尽量、争取把官网的例子也逐步一一实现,或者大部分常用的实现一下。

感谢团队好友hihiyou(http://www.hihiyou.com)为我找了一个可以在windows下使用的Imagick的DLL,可以让我开始学习它。

先来个例子,黑黑。。。

PHP代码
  1. <?php  
  2. header('Content-type: image/gif');  
  3.   
  4. $image = new Imagick('google_logo.gif');  
  5. $image->adaptiveResizeImage(400,NULL);  
  6.   
  7. echo $image;  
  8. ?>  

原图:

 

大小: 8.36 K
尺寸: 276 x 110
浏览: 2032 次
点击打开新窗口浏览全图

重生成:

大小: 18.96 K
尺寸: 400 x 159
浏览: 1881 次
点击打开新窗口浏览全图

Tags: imagick, php, extension, dll

闲着无聊,用WPS生成文档

不好意思,该操作只能在windows服务器上才能执行,是因为,只有windows服务器才支持COM功能,而且,必须安装wps(这点应该不难,因为WPS是免费软件)
免费软件这点太重要了,如果你要生成WORD,你不可能安装一个OFFICE吧,office太贵了。

PHP代码
  1. <?php  
  2. $wps = new COM("WPS.Application");  
  3. $wps->Visible = false;  
  4. $doc = $wps->Documents->Add();  
  5. $doc->Range->Text = 'WPS FOR PHP test';  
  6. $doc->Paragraphs[1]->Alignment = 1;  
  7. $doc->Shapes->AddPicture("http://img.kingsoft.com/publish/kingsoft/images/gb/sy/logo.gif", 100, 50, 148, 60);  
  8. $doc->SaveAs('c:\\temp\\test1.wps');  
  9. $doc->Close();  
  10. $wps->Quit();  
  11. unset( $doc , $wps );  
  12. ?>  

代码很简单,只是添加了一个文字和一个图片而己。但是,证明了是可以使用这个功能。
大家别忘了,WPS的附加功能可是很多的,比如把文件转为PDF等格式。也就是说, 如果是在windows服务器上,我们要生成PDF,可以不使用那些什么fpdf类库,而是使用WPS先生成一个WORD格式的文档,然后直接exportPdf就可以了。要知道OFFICE默认并不支持这种功能。黑黑

这也是一种思路嘛,思路决定出路,转换一种思路,可能就是海阔天空。

这里是WPS的开发者网站:http://wps.kingsoft.com/apply/engineer.shtml,从这里可以下载API:http://wps.kingsoft.com/download/WPSAPI.zip

Tags: php, wps, com, wps application

佛家思想与PHP开发

今天听了点课,感悟还是有点的。软件开发会时不时的遇到点瓶颈,这其实与佛家思想还是有点关系的,当然,也许是我硬套上的吧。

佛家参惮有一种说法:看山是山,看水是水;看山不是山,看水不是水;看山还是山,看水还是水。这里说的是佛家修行的三个层次,也叫三重境界,即初期看山是山,中期有悟时,山就不再是简单的山了,最后彻悟,返朴归真,山还是山,但已经不是原来的那个山了,升华了,空灵了。把这用在游记上也是很合适的。走马观花,照象机式的记录,见山是山,见水是水,见什么写什么,流水帐,千篇一律,大同小异,这是初级阶段。再上一个层次,进到文学的创作,那就得看山不是山,看水不是水。那是什么?是山水背后的东西,附在山水之上的东西,山不再是单纯岩石泥土加草木的立体,水也不是简单的流动的液体了。

软件开发也差不多,刚开始学程序的时候,看山是山,因为这时候思想还没有成形,对于程序的理解都是停在表面上,没有什么特别的概念。随着编程时间的增长,和能力的进步,这时候看待程序、架构都比较的深层次了,于是就升级成为看山不是山,看水不是水的境界。这道坎其实很难跨越,等到真正跨越这一层,然后所以的编程语言、架构在眼里又变成那样的浅显,于是又回到了最初的看山是山看水是水的境界。

随便说说而己。不必生搬硬套

Tags: 佛家思想, 感悟, 开发, php

[翻译][未完成版本]Developing Desktop Applications in PHP for Beginners.

Introduction:
简价

We have been creating web-applications using PHP since it came into existence, now we can also develop Desktop or Stand alone Applications with PHP-GTK. Desktop Applications are one which does not need either a Web Server like IIS, Apache, PWS etc. or a web browser for their execution. One of the reasons why Java is so popular is because it can be used to build applications, web pages, applets and beans that can run on several platforms including Windows, Linux and Solaris. Java runs a virtual machine called JVM, and code is compiled into an intermediate format known as Java byte code, which is platform independent. When that particular piece of code is executed within the JVM, the JVM optimizes the code for the particular platform on which it is running as it is being compiled.
从PHP产生到现在,我们一直都是使用它创建WEB应用,如今,我们也可以使用PHP-GTK来创建桌面或者其他杰出的应用。桌面程序不再依靠WEB服务器(比如IIS、APACHE、PWS等等)或者通过浏览器运行他们。JAVA为什么这么流行其中之一的原因就是他不仅可以创建程序、WEB应用,小应用程序Applets和Beans,而是他可以运行在windows、linux和solaris平台上。当这些特定的代码在JVM上运行的时候,JVM会在编译的时候针对特定联台而对代码进行优化。

Microsoft's latest technology, .NET follows the same principles. Code is compiled into Microsoft Intermediate Language (MSIL) and is then executed within the .NET framework as an application domain. Microsoft is hoping to standardize C# and MSIL so that .NET code can run cross platform.

微软最近的技术声称,.net一直遵循着同样的工作原因,代码被编译成MSIL并且运行在.net framework上。微软一直希望C#和MSIL能够标准化,这样.net下的代码也就能够相对的跨平台运行了。

So what has all of this got to do with PHP-GTK? Well, both Java and .NET can be used to build windowed applications and web pages. Thanks to PHP-GTK, we can now build cross platform windowed applications with PHP as well.

可是这和使用PHP-GTK又有什么关系呢?OK,java和.net都能够创建“窗口式应用”(桌面应用软件)和网页。感谢PHP-GTK,我们也可以使用PHP创建跨平台的“winform应用”(windowed applications一直不知道怎么翻译比较好,下面如果再提到,我想,我还是用桌面应用软件来代替吧。)。

What is PHP-GTK?
PHP-GTK是什么?

GTK is an acronym for the GIMP Toolkit and GIMP is an acronym for GNU Image Manipulation Program, and is a fully featured graphics editing program that runs on Linux. It has many (if not all) of the features of popular Windows programs such as Photoshop and Paint shop. It's the graphics editor of choice for most Linux users.

GTK是GIMP ToolKit(GIMP工具包)的缩写,同时GIMP又是GNU Image Manipulation Program(开源图像处理软件)的缩写,是一个可以运行在LInux下的一款图像编辑程序。它拥有与windows平台下的photoshop和画笔程序一些相同的功能,但并非全部。它是大多数Linux用户所选择的图形编辑工作。

GTK is actually part of a set of libraries that was written in C called GTK+. GTK+ was built up over time and is now a main part of Gnome, which is a Linux GUI desktop environment. GTK+ is based on an object-oriented nature and also includes two other libraries:
GTK实际上是一套用C语言编码的代码库,一般称为GTK+。GTK+一直以来就是Gnome(Linux图形界面)的重要部件之一。GTK+采用了面向对象的方面,并且引入其他两个重要的库:

  1. GLib: A library of tools that can be used to assist developers when creating applications with GTK+.
  2. GDK: Similar to GDI for Win32, GDK standard for GIMP drawing kit and wraps a set of lower level drawing functions into classes that make developing applications with GTK+ easier. If you're thinking along the lines of MFC for C++ then you're making a fair comparison: MFC wraps several controls and hides the calls to the underlying Windows API's from the developer. GDK does the same thing for GTK+.

Where to get?

We can download binary as well as source code version of PHP-GTK from http://gtk.php.net/download.php . As a beginner, it would be a difficult process to download and install in this manner. Where we need to set up another php.ini file for PHP-GTK. Instead there is another way of installing it. We can get PHP-GTK2 in an executable form as we get WAMP.EXE. (Windows, Apache, Mysql, PHP) All we have to do is just download just download the files from http://www.gnope.org/download.php ,unzip them and double click on the icon GnopeSetup-1.5.1.exe . It will run through a step by step process where it will set up PHP-GTK automatically.

How to test the installation?

Once the installation is done we would eager to know about what is special in it? When we install PHP we would run phpinfo () from root directory .For this let us run a sample script which displays Hello world (as usual) .we can use Dreamweaver for editing the code. Another important point to be kept in mind is to save the file with extension .phpw it can be saved anywhere on your hard disk.

Here is the sample code:

 

<?PHP
if (!class_exists('gtk')) {
die("Please load the php-gtk2 module in your php.ini");
}
$wnd = new GtkWindow();
$wnd->set_title('Hello world');
$wnd->connect_simple('destroy', array('gtk', 'main_quit'));
$lblHello = new GtkLabel("hello world");
$wnd->add($lblHello);
$wnd->show_all();
Gtk::main();
?>

 

I have saved this sample file with the name hello.phpw at c:\test\. We should run this sample code from command line interface. (CLI) There may be a question rising in your mind asking, why we should run through command prompt than by just by double clicking it as it is a stand alone application. It is possible, for that we need to have a PHP compiler which converts our PHP-GTK code to EXE file . For now, let us try running it from the command prompt.
现在我们将上面这段代码保存在c:\test\目录下,取名为:hello.phpw。我们可以在命令行下运行它。或许你会有疑问,为什么我们不是编译成一个正常的程序,可以通过双击来运行?当然,这不是问题,那样的话,我们需要通过我们的PHP-GTK程序把PHP代码转换成EXE文件。现在,让我们尝试运行一下这个命令行先。

Steps for Executing a sample code:
执行部骤

  1. Start -> Run -> cmd (for xp sp2 and later version) or command (for windows 98).
    点击开始菜单->运行,输入cmd,如果是windows2000以前的版本,请输入command。
  2. Now you could see a black window which is Command Prompt. Key in the following commands as shown below.

 

z:>c:
c:> cd test
c:\test>php hello.phpw

Once we finish this line and hit the Enter key, we should see the desired output.

This shows the successful installation of PHP-GTK2 and shouls us PHP output without a web-browser.

Some interesting Websites on PHP-GTK:

  1. http://www.kksou.com/php-gtk2/
  2. http://phpgtk.activeventure.com/gtk/gtk.gtkbox.html (describes about all base classes).
  3. http://gtk.php.net/download.php
  4. http://www.gnope.org/download.php

Tags: gtk, php, application, develop, desktop

恭喜一下,phpmyadmin出了3.0测试版

看新闻的时候,突然看到phpmyadmin出了3.0beta版本,只是好象新版本是基于5.2开发的。源码地址为:http://internap.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-3.0.0-beta-all-languages.zip,大家可以去下载,如果不能下载,可以先到:http://sourceforge.net/projects/phpmyadmin/,找到3.0beta版进行下载。

对于使用PHP进行开发的人员来说,phpmyadmin可以说是最常用的工具之一。其重要性不亚于一个好的IDE所带来的功效。

SF上面如此提示:

Welcome to the beta release of phpMyAdmin 3.0.0. This version supports various features of MySQL 5.1, the Maria and PBXT storage engines and  
SweKey hardware authentication. The 3.0 series requires PHP 5.2+ and MySQL 5.0+.

看到cnbeta上有人评价说:phpmyadmin不是利器,而是神器。心中亦有此感啊。

下载源码,学习一下。oh yeah

Tags: phpmyadmin, php, mysql, database, management