官术网_书友最值得收藏!

  • Python Multimedia
  • Ninad Sathaye
  • 491字
  • 2021-08-03 15:27:42

Time for action – play with Thumbnail Maker application

First, we will run the Thumbnail Maker application as an end user. This warm-up exercise intends to give us a good understanding of how the application works. This, in turn, will help us develop/learn the involved code quickly. So get ready for action!

  1. Download the files ThumbnailMaker.py, ThumbnailMakeDialog.py, and Ui_ThumbnailMakerDialog.py from Packt website. Place these files in some directory.
  2. From the command prompt, change to this directory location and type the following command:
     python ThumbnailMakerDialog.py
    

    The Thumbnail Maker dialog that pops up was shown in the earlier screenshot. Next, we will specify the input-output paths and various image parameters. You can open any image file of your choice. Here, the flower image shown in some previous sections will be used as an input image. To specify an input image, click on the small button with three dots . It will open a file dialog. The following illustration shows the dialog with all the parameters specified.

  3. If Maintain Aspect Ratio checkbox is checked, internally it will scale the image dimension so that the aspect ratio of the output image remains the same. When the OK button is clicked, the resultant image is saved at the location specified by the Output Location field and the saved image is displayed in the right-hand panel of the dialog. The following screenshot shows the dialog after clicking OK button.
  4. You can now try modifying different parameters such as output image format or rotation angle and save the resulting image.
  5. See what happens when the Maintain Aspect Ratio checkbox is unchecked. The aspect ratio of the resulting image will not be preserved and the image may appear distorted if the width and height dimensions are not properly specified.
  6. Experiment with different re-sampling filters; you can notice the difference between the quality of the resultant image and the earlier image.
  7. There are certain limitations to this basic utility. It is required to specify reasonable values for all the parameters fields in the dialog. The program will print an error if any of the parameters is not specified.

What just happened?

We got ourselves familiar with the user interface of the thumbnail maker dialog and saw how it works for processing an image with different dimensions and quality. This knowledge will make it easier to understand the Thumbnail Maker code.

Generating the UI code

The Thumbnail Maker GUI is written using PyQt4 (Python bindings for Qt4 GUI framework). Detailed discussion on how the GUI is generated and how the GUI elements are connected to the main functions is beyond the scope of this book. However, we will cover certain main aspects of this GUI to get you going. The GUI-related code in this application can simply be used 'as-is' and if this is something that interests you, go ahead and experiment with it further! In this section, we will briefly discuss how the UI code is generated using PyQt4.

主站蜘蛛池模板: 隆回县| 大埔县| 桃源县| 苍梧县| 郸城县| 肃北| 湛江市| 鄂托克旗| 通渭县| 九寨沟县| 依安县| 澄江县| 旬阳县| 新河县| 宜都市| 西畴县| 建昌县| 茂名市| 湘阴县| 古丈县| 淮阳县| 托克托县| 达孜县| 长宁县| 宁南县| 文山县| 巩留县| 阿尔山市| 诸暨市| 岑溪市| 绥宁县| 永福县| 垫江县| 洛川县| 大连市| 巴塘县| 葫芦岛市| 突泉县| 略阳县| 揭西县| 易门县|