Pas de compte !!!
Documentations > WIKI > WIKI pour WideImage_for_xoops > Use WideImage_for_xoops [english Version]

Use WideImage_for_xoops [english Version]

Publié par montuy337513 le 24-Feb-2013 14:30 (3253 lectures)

To start

To start, you must call WideImage_for_xoops Frameworks for using the features of the image processing in your module.

For exemple:

if (is_file(XOOPS_URL.'/Frameworks/WideImage/WideImage.php')) {
    include_once XOOPS_URL.'/Frameworks/WideImage/WideImage.php');
} else {
     die('Frameworks WideImage absent');
}

To avoid a possible deadlock when installed by a person who has not loaded the prerequisites, I insert this code in the index.php file of my administration section.

if (!is_file(XOOPS_ROOT_PATH.'/Frameworks/WideImage/WideImage.php')) {
    $fram_wideimage = _AM_ABSENT;
} else {
    $fram_wideimage =_AM_PRESENT;
}
$clr_fram_wideimage = ($fram_wideimage == _AM_ABSENT) ? 'red': 'green';
$indexAdmin->addInfoBox(_AM_GEST_FRAMEWORKS);
$indexAdmin->addInfoBoxLine(_AM_GEST_FRAMEWORKS,_AM_CHG_WIDEIMAGE, $fram_wideimage, $clr_fram_wideimage);



 and this code in my language module directory in admin.php

(exemple : ./modules/my_module/language/english/admin.php)

define('_AM_GEST_FRAMEWORKS', 'Manage Frameworks');
define('_AM_ABSENT', 'Not OK');
define('_AM_PRESENT', 'OK');
define('_AM_CHG_WIDEIMAGE', 'Frameworks WideImage_for_xoops version 1.00 minimum : %s');



 Basic exemplec

 

Most of you will use the WideImage_for_xoops Frameworks for thumbnail creation when downloading images, here is how to resize image 150x100 pixels with WideImage_for_xoops:

$image = WideImage::load('image.jpg'); //load picture in memory 
$resized = $image->resize(150,100); // Resize picture in 150x100px
$resized->saveToFile('miniature.jpg'); // Save a new picture


 

 

Resize function

 

In this chapter, we will further detail the parameters of the function of resizing

resize( [mixed $width = null], [mixed $height = null], [string $fit = 'inside'], [string $scale = 'any'])



$witdh and $height respectively correspond to the width and height of the resized image.

These variables fixed positive integers accept or negative (100 coorespond the size in pixels, and -20 specifies reduce the original size of 20 pixels), but we also specified percentages positive or negative (50% corresponds to an increase 50% of the image size and 20% corresponds to a 20% reduction of the image).
In cases where values are missing, the redimenssionement will caluclé from the ratio of the other dimension.

$fit as can be made inside, outside or fill.

  • inside : for the image size is at most equal to width and height ratio is preserved
  • outside : for the size of the image is at least equal to the width and height, the ratio is preserved
  • fill : Resize an image to exactly fit a width×heighht box by passing ‘fill’ as the value of $fit parameter. The image will be stretched as necessary, aspect ratio may not be kept.

 

Possible values include any(default), down and up:

  • down : resize if image is larger than the new dimensions
  • up : resize if image is smaller than the new dimensions
  • any : resize regardless of the image size

La fusion (watermark)

Applying a watermark (or merging) is done with the merge() method. You have to pass another image object, coordinates and opacity. If coordinates aren’t given, the image is merged at (0, 0). If opacity isn’t specified, value 100 is used.

An example of merge with opacity 30 to position 10, 10:

$img = WideImage::load('image.jpg');
$watermark = WideImage::load('logo.jpg');
$new = $img->merge($watermark, 10, 10, 30);


Merge operation supports smart coordinates. So you can easily place the watermark relative to the right or bottom edge.

$img = WideImage::load('pic.jpg');
$watermark = WideImage::load('logo.jpg');
// Logo.jpg is 50x30 in size 

// Place the logo directly in the center (x), 10px from bottom (y) 
$new = $img->merge($watermark, '50% – 25', '100% – 40', 50);
// Or use alignment labels, it's prettier
$new = $img->merge($watermark, 'center', 'bottom – 10', 50);


By placing the watermark is on the fly, but you can very well when loading integrate the watermark, save the result and use it to display the new image obtained.


Naviguer à travers les articles
Article précédent Utilisation de WideImage_for_xoops
Les commentaires appartiennent à leurs auteurs. Nous ne sommes pas responsables de leur contenu.
Auteur Commentaire en débat

Extraits de nos produits en téléchargement

Publicité