dolibarr 21.0.0-beta
images.lib.php File Reference

Set of function for manipulating images. More...

Go to the source code of this file.

Functions

if(!defined( 'IMAGETYPE_WEBP')) getDefaultImageSizes ()
 Return default values for image sizes.
 
 getListOfPossibleImageExt ($acceptsvg=0)
 Return if a filename is file name of a supported image format.
 
 image_format_supported ($file, $acceptsvg=0)
 Return if a filename is file name of a supported image format.
 
 dol_getImageSize ($file, $url=false)
 Return size of image file on disk (Supported extensions are gif, jpg, png, bmp and webp)
 
 dol_imageResizeOrCrop ($file, $mode, $newWidth, $newHeight, $src_x=0, $src_y=0, $filetowrite='', $newquality=0)
 Resize or crop an image file (Supported extensions are gif, jpg, png, bmp and webp)
 
 dolRotateImage ($file_path)
 dolRotateImage if image is a jpg file.
 
 correctExifImageOrientation ($fileSource, $fileDest, $quality=95)
 Add exif orientation correction for image.
 
 vignette ($file, $maxWidth=160, $maxHeight=120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0)
 Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
 
 imgAddEditDeleteButton ($htmlid, $urledit, $urldelete)
 Beautify an image by adding a link edit and delete on image.
 

Detailed Description

Set of function for manipulating images.

Definition in file images.lib.php.

Function Documentation

◆ correctExifImageOrientation()

correctExifImageOrientation ( $fileSource,
$fileDest,
$quality = 95 )

Add exif orientation correction for image.

Parameters
string$fileSourceFull path to source image to rotate
string | bool | null$fileDeststring : Full path to image to rotate | false return gd img | null the raw image stream will be outputted directly
int<-1,100>$quality output image quality
Returns
bool : true on success or false on failure or gd img if $fileDest is false.

Definition at line 436 of file images.lib.php.

Referenced by dolRotateImage().

◆ dol_getImageSize()

dol_getImageSize ( $file,
$url = false )

Return size of image file on disk (Supported extensions are gif, jpg, png, bmp and webp)

Parameters
string$fileFull path name of file
bool$urlImage with url (true or false)
Returns
array{width:int,height:int}|array{}|array{width:'',height:''} array('width'=>width, 'height'=>height)

Definition at line 145 of file images.lib.php.

References dol_osencode(), and image_format_supported().

Referenced by pdf_standard_member\Add_PDF_card(), pdf_standardlabel\Add_PDF_label(), pdf_getHeightForLogo(), pdf_getSizeForImage(), and CommonObject\show_photos().

◆ dol_imageResizeOrCrop()

dol_imageResizeOrCrop ( $file,
$mode,
$newWidth,
$newHeight,
$src_x = 0,
$src_y = 0,
$filetowrite = '',
$newquality = 0 )

Resize or crop an image file (Supported extensions are gif, jpg, png, bmp and webp)

Parameters
string$filePath of source file to resize/crop
int$mode0=Resize, 1=Crop
int$newWidthLargeur maximum que dois faire l'image destination (0=keep ratio)
int$newHeightHauteur maximum que dois faire l'image destination (0=keep ratio)
int$src_xPosition of croping image in source image (not use if mode=0)
int$src_yPosition of croping image in source image (not use if mode=0)
string$filetowritePath of file to write (overwrite source file if not provided)
int$newqualityValue for the new quality of image, for supported format (use 0 for maximum/unchanged).
Returns
string File name if OK, error message if KO
See also
dol_convert_file()

Definition at line 186 of file images.lib.php.

References dol_osencode(), dol_syslog(), dolChmod(), and image_format_supported().

◆ dolRotateImage()

dolRotateImage ( $file_path)

dolRotateImage if image is a jpg file.

Currently use an autodetection to know if we can rotate. TODO Introduce a new parameter to force rotate.

Parameters
string$file_pathFull path to image to rotate
Returns
boolean Success or not

Definition at line 422 of file images.lib.php.

References correctExifImageOrientation().

◆ getDefaultImageSizes()

if(!defined('IMAGETYPE_WEBP')) getDefaultImageSizes ( )

Return default values for image sizes.

Returns
array{maxwidthsmall:int,maxheightsmall:int,maxwidthmini:int,maxheightmini:int,quality:int} Array of default values

Definition at line 45 of file images.lib.php.

Referenced by CommonObject\addThumbs(), dol_add_file_process(), EmailCollector\saveAttachment(), and FormFile\showImageToEdit().

◆ getListOfPossibleImageExt()

getListOfPossibleImageExt ( $acceptsvg = 0)

Return if a filename is file name of a supported image format.

Parameters
int$acceptsvg0=Default (depends on setup), 1=Always accept SVG as image files
Returns
string Return list of image formats

Definition at line 68 of file images.lib.php.

References getDolGlobalString().

Referenced by getImagePublicURLOfObject(), getNbOfImagePublicURLOfObject(), getPublicFilesOfObject(), and image_format_supported().

◆ image_format_supported()

image_format_supported ( $file,
$acceptsvg = 0 )

Return if a filename is file name of a supported image format.

Parameters
string$fileFilename
int$acceptsvg0=Default (depends on setup), 1=Always accept SVG as image files
Returns
int -1=Not image filename, 0=Image filename but format not supported for conversion by PHP, 1=Image filename with format supported by this PHP

Definition at line 85 of file images.lib.php.

References getListOfPossibleImageExt().

Referenced by Ticket\copyFilesForTicket(), dol_add_file_process(), dol_getImageSize(), dol_imageResizeOrCrop(), BOM\is_photo_available(), Product\is_photo_available(), Categorie\isAnyPhotoAvailable(), FormFile\list_of_documents(), Product\liste_photos(), EmailCollector\saveAttachment(), CommonObject\show_photos(), and vignette().

◆ imgAddEditDeleteButton()

imgAddEditDeleteButton ( $htmlid,
$urledit,
$urldelete )

Beautify an image by adding a link edit and delete on image.

Parameters
string$htmlidID of HTML img tag
string$urleditURL to submit to edit Image
string$urldeleteURL to call when deleting the image
Returns
string HTML and JS code to manage the update/delete of image.

Definition at line 836 of file images.lib.php.

◆ vignette()

vignette ( $file,
$maxWidth = 160,
$maxHeight = 120,
$extName = '_small',
$quality = 50,
$outdir = 'thumbs',
$targetformat = 0 )

Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).

If file is myfile.jpg, new file may be myfile_small.jpg

Parameters
string$filePath of source file to resize
int$maxWidthMaximum width of the thumbnail (-1=unchanged, 160 by default)
int$maxHeightMaximum height of the thumbnail (-1=unchanged, 120 by default)
string$extNameExtension to differentiate thumb file name ('_small', '_mini')
int$qualityQuality of compression (0=worst, 100=best)
string$outdirDirectory where to store thumb
int$targetformatNew format of target (IMAGETYPE_GIF, IMAGETYPE_JPG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_WBMP ... or 0 to keep old format)
Returns
string|int<0,0> Full path of thumb or '' if it fails or 'Error...' if it fails, or 0 if it fails to detect the type of image

Definition at line 520 of file images.lib.php.

References dol_mkdir(), dol_osencode(), dol_syslog(), dolChmod(), getDolGlobalString(), getImageFileNameForSize(), and image_format_supported().

Referenced by CommonObject\addThumbs(), Ticket\copyFilesForTicket(), FileUpload\createScaledImage(), dol_add_file_process(), EmailCollector\saveAttachment(), and FormFile\showImageToEdit().