Beginner’s Guide to Cropping Images in PHP Using ImageMagick

While using images in a web application, developers can’t always include images of a particular measurement. In such cases, resizing the images for the application would be a good option but, not efficient either. For example, resizing a long vertical image into a horizontal dimension would just squeeze the image; thereby, affecting the aesthetics of the website and also reducing the purpose of it. Hence it would be smart to implement a cropping tool like ‘ImageMagick’ in order to fit images of various dimensions into a specified size.

ImageMagick is a collection of robust and convenient tools for manipulating images. It can be used to crop images of numerous formats such as JPEG, PNG, GIF, TIFF, PhotoCD and many more. ImageMagick facilitates creation of dynamic images that are fitting to the specific requirements of web applications.

Difference Between Cropping in GD Library and ImageMagic:

GD is the most commonly used extension for PHP. It is popular because it is easier to install and configure (`yum install php-gd` on Fedora, CentOS etc or `sudo apt-get php5-gd` on ubuntu). However, it has some limitations such as:

  • It is comparatively slower
  • It is more memory intensive
  • For certain aspects it can be more complex to use.

Below I have mentioned a sample code for image cropping using GD:

[sourcecode]<?php
function resize_my_image($file, $w, $h, $crop=FALSE) {
list($width, $height) = getimagesize($file);
$r = $width / $height;
if ($crop) {
if ($width > $height) {
$width = ceil($width-($width*($r-$w/$h)));
} else {
$height = ceil($height-($height*($r-$w/$h)));
}
$newGDwidth = $w;
$newGDheight = $h;
} else {
if ($w/$h > $r) {
$newGDwidth = $h*$r;
$newGDheight = $h;
} else {
$newGDheight = $w/$r;
$newGDwidth = $w;
}
}
$src = imagecreatefromjpeg($file);
$dst = imagecreatetruecolor($newGDwidth, $newGDheight);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $newGDwidth, $newGDheight, $width, $height);

return $dst;
}

$img = resize_my_image(‘/path/to/some/image.jpg’, 150, 150);
?>[/sourcecode]

You can either output it to the browser or save it to a file using the ‘imagejpeg’ function.

Imagick:

Imagick is a less frequently used PECL extension. ImageMagick is a free tool that is used for creating and manipulating images that supports over 100 different image formats. This can be used on a command line tool for any programming language. The Imagick extension essentially provides an API for all of the functionalities available in the `convert` command line tool.

Some of its advantages are:

  • It is faster
  • It uses less memory
  • Offers more powerful functionality
  • Imagick’ is lot easier to use (once you figure out how), your code may end up smaller and cleaner.

The down side of using this extension is that the documentation is extremely limited and there are almost no examples available on the web. Installation on the other hand can be a painful task as well.

Although it should just be a matter of running the command `pecl install imagick`.

Sample code:

Cropping larger images:

Put a big picture named andolasoft_logo.jpg along side with your php page, run the test and check the directory to see andolasoft_logo_thumb.jpg.

Requirement:

imagemagick with imagick extension

[sourcecode]<?php
$obj = new imagick(‘andolasoft_logo.jpg’);
//resize the above image
$obj->thumbnailImage(160, 0);
//write the thumb
$obj->writeImage(‘andolasoft_logo_thumb.jpg’);
?>[/sourcecode]

To Crop Animated Image:

[sourcecode]<?php
$image = new imagick(“andolasoft_animated_logo.gif”);
$image = $image->coalesceImages(); // the trick! To crop animated image
foreach ($image as $frame) {
$frame->cropImage($width, $height, $x, $y);
$frame->setImagePage(0, 0, 0, 0); // Remove gif canvas
}
?>[/sourcecode]

$x → The X coordinate of the cropped region’s top left corner
$y → The Y coordinate of the cropped region’s top left corner

Implementing ‘ImageMagick’ would make the website look clean and flawless. Images on the other hand retain its look and feel, thereby making the application look professional and optimized.

Find anything amiss here, then share it with us.

Why is CakePHP Popular For Web App Development

Web application development is a competitive field with new frameworks and tools emerging almost every day. If you are looking to create a dynamic website or web app, you may be wondering which framework will best suit your needs. When it comes to choosing the right technology for your project, there are many factors to consider. Below, we’ll review some of the benefits of using CakePHP  and why is CakePHP popular for web app development.

What is CakePHP?

CakePHP is a free and open-source platform, which facilitates the developers to build highly affordable web-applications using the MVC framework. This is a robust and efficient platform for the developers to create exciting PHP web applications.

What Makes CakePHP Popular?

Here I would like to discuss the aspects responsible for popularizing CakePHP among developers.

  • Easy-To-Use Functionality

    Developers are constantly looking for ways to make development process easier and hassle-free. Hence we can use code generation and scaffolding features built-in in CakePHP to rapidly build prototypes.

Never miss an update from us. Join 10,000+ marketers and leaders.

CakePHP facilitates this opportunity which adds to its popularity. With CakePHP, the application development is not burdened with writing complex codes for the application hence saves a lot of development time. The code lines are also simplified and reduced to facilitate the developers with productive development process.

  • Flexible And Versatile

    CakePHP is used for web app development is because the configuration is flexible and versatile. It can automatically cater itself based on the requirements of the developers and the changes made by them. Hence, it doesn’t require any elaborate configuration settings for project development. Most features and settings are auto detected in the system and require only the settings for database connections. It’s a feature rich light weight PHP framework comes with lot of features like code generation, translations, database access, caching, validation, authentication etc.

  • MVC (Model View Control) Architecture

    CakePHP development uses the model-view-control architecture which helps in distinguishing the business logic from data and design. It does a clear discrimination among the presentation layer, the business logic and database. It enables the developers to work independently on separate aspects of development at the same time. It enables the developers to develop faster and make optimum use of the resources.

  • Security

    The security of the application must be top notch such that they make the website full proof from any security breaches and is safe from the hands of hackers. CakePHP comes with built-in tools for input validation, CSRF protection, Form tampering protection, SQL injection prevention, and XSS prevention, helping you keep your application safe & secure. 

  • Friendly License

    CakePHP is licensed under the MIT license which makes it perfect for use in commercial applications.

CakePHP Development has become the foremost option for web developers as well as the Businesses to build exciting and unique applications. No wonder it is one of the most preferred MVC framework.

Planning something on CakePHP? Get in touch with Andolasoft’s Experts to discuss your idea.

CakePHP is Faster Development Of Next Generation Web Application

There are numerous PHP frameworks available such as Zend, CodeIgniter, Akelos etc. CakePHP on the other hand is the most popular framework among them and reduces significant coding time and investment. It is an open source web application development tool. It helps to build the web pages and applications faster and simpler.

Some features of CakePHP framework

  • Compatible with almost all PHP versions
  • Facilitates code scaffolding for faster development of prototypes
  • Doesn’t require any complex configuration
  • This framework is safe and secure:  It provides in-built tools for input validation, XSS prevention, SQL prevention for secure application development.
  • It provides built-in view helpers for AJAX, JavaScript, HTML etc.
  • It offers faster and flexible tempting features as well as data validation features

Never miss an update from us. Join 10,000+ marketers and leaders.

These features make installation and use of CakePHP easy which in turn makes PHP more manageable. As it is an open source, it can be customized according to the needs of specific business requirements. It provides the CakePHP developers with MVC framework, Class inheritance, re-usability, Ajax support and many more to make the development process easier and effortless.  It assists the PHP developers at all levels and provide the ability to manage every part of project development.

Conclusion

It has a lot of advantages over other PHP frameworks, such as less code, less maintenance, and more scalability. CakePHP team works tirelessly to make sure that programmers who want to use CakePHP can do so in an easy and enjoyable way. CakePHP itself is easy to use, and the framework has many features to make life easier for developers who need to create applications that work well and scale to large numbers of users.

Our CakePHP development team is highly experienced to deliver robust, logical, most reliable and effective solutions to our global clients. Our expertise in CakePHP development helps us for building cost effective apps that too matching customer budget with quick turn-around time.

Awesome Project collaboration Tool to Manage Your Project and Team

When project development is in progress, practically each of the members may not meet face to face at a single workplace, neither the communication/documentation be available at the same location.

In order to overcome these hurdles, Andolasoft designed and developed a unique project collaboration tool called ‘Orangescrum’ with lots of facility and flexibility.

It is developed using CakePHP with very simple yet intuitive interfaces with easy-to-use functionalities which distinct it from other similar tools. It efficiently handles projects by maintaining effective communication among the project members with some brilliant features as discussed below

Orangescrum allows you to share files while assigning tasks to the developers for your projects. It is taken care of that the popular format (.doc, .docx, .xls, .html etc) are supported. This is extremely helpful for relating tasks with additional information in the form of documents.

  • Create and track all the task of a milestone from a single page. Milestones can be set as per the project deadline so that the stakeholders are alerted. Also tasks can be streamlined for each milestone and assigned them to concerned project members.
  • It uses a ticketing workflow to create a new task while addressing the issue. These tasks can then be assigned to specific team members in different phases. It facilitates to manage through various phases such as ‘NEW’, ‘WIP’, ‘START’ and ‘CLOSE’
  • It can also be used as a bug tracker or issue tracker. It includes filters and options to make issue tracking easier by assigning it to the concerned project members.
  • You can set email or mobile alerts to anyone involved in a project, which can be prioritized and targeted to concerned individuals. It also facilitates the receiver to reply directly from the web mail which is automatically updated in Orangescrum.
  • It includes the ‘Archive’ facility for safe storage of files and tasks. This feature helps to keep the files and task safe. These contents can later be retrieved at any time, unless it is removed permanently.

To know more about Orangescrum, please visit:  www.orangescrum.com

Why CakePHP is Popular? And The Role Of CakePHP Developer

CakePHP is an open source PHP based rapid development framework. It offers great run-time infrastructure along with abundant set of libraries for CakePHP developers. Cake PHP development is supported by the MVC (Model View and Controller) architecture which differentiates the programming logic from the data presentation layer.

It also features other programming concepts like Front Controller, Association Data Mapping and Active Record. Along with these, there are numerous other features that make CakePHP one of the most preferred web development frameworks among others.

Let’s take a look at some features here

Wide Community:

CakePHP developers are supported by huge peers who make use of this framework. There are many contributors and programmers who share the community. For this reason, using the framework is simpler for development as well as for research.

Never miss an update from us. Join 10,000+ marketers and leaders.

Reusability:

It facilitates the developers in saving a lot of efforts through PHP development. Because the programmer make use of a pre-written code for more than one project. In other words, they can focus on the logical and creative part of application whereas the tedious task of coding could be handled with ease.

Open Source:

The framework is open source, for which the CakePHP developers do not have to spend any amount in the process of development and have complete access to its source code. It also assists the developers in adding robustness and improves performance in web applications.

Some of the roles of CakePHP developers include

    • Manage development efforts and framework efficiently
    • Support product releases
    • Ability to handle lot of projects in less time
    • Overall review of the quality & progress of the work
    • Support stable user growth

Conclusion

Here at Andolasoft we provide our customers with a unique and up-to-date approach towards their Web-app development. We design and develop intriguing web applications using PHP/CakePHP. We follow agile development approach to deliver project on time and within budget to our customer

CloudLinux’s Recent Integration of PHP 5.5 Alpha 2 Version

Shared hosting operating system provider CloudLinux has expanded their PHP offerings by declaring the availability of PHP 5.5 Alpha2 version to its PHP selector tool.

With the ability to select PHP versions, PHP selector allows the users to get the latest feature updates

and preferred PHP version like PHP 5.2, 5.3, 5.4, and now, 5.5 Alpha2 from their web hosting control panel. CloudLinux places each individual website in a virtual private server.

Never miss an update from us. Join 10,000+ marketers and leaders.

Each account is then assigned a specific amount of hardware resources and a desirable PHP version, by using the PHP selector tool.

PHP 5.5 Alpha2 version includes new features like the most awaited password hashing API and providing users the ability to use bcrypt along with loop-controlling generators.

Igor Seletskiy the CEO of CloudLinux has expressed that the availability of PHP selector has made it easier to get access to PHP features. He quoted “PHP is possibly the most widely used aspect of any shared web hosting plan.”

Igor Seletskiy also added “Like the rest of the web hosting community, we are excited to start exploring the new features of PHP version 5.5.

However, many hosting companies and their customers would not usually deploy an Alpha version on a large-scale, server-wide basis.

CloudLinux and PHP Selector make it possible for hosting providers to assign individual accounts their own PHP version without affecting other sites on the same hardware.” Integrating such features in CloudLinux has helped PHP development to become easier and more productive