Skip to main content
Inspiring
March 13, 2017
Question

CFimage resize

  • March 13, 2017
  • 5 replies
  • 2900 views

Bonjour,

Quand je veux redimensionner une image (.jpg), j'ai le message suivant :

The  ServerFile image format is not supported on this operating system

mais quand je n'utilise pas cette fonction, le serveur accepte !

<cfimage action="resize" source="File.ServerFile" height="300" width="200" name="resized">

Merci d'avance pour votre aide

    This topic has been closed for replies.

    5 replies

    BKBK
    Community Expert
    Community Expert
    March 17, 2017

    ZNB  wrote

    Bonjour,

    Quand je veux redimensionner une image (.jpg), j'ai le message suivant :

    The  ServerFile image format is not supported on this operating system

    mais quand je n'utilise pas cette fonction, le serveur accepte !

    <cfimage action="resize" source="File.ServerFile" height="300" width="200" name="resized">

    Merci d'avance pour votre aide

    <cffile

        action = "upload"

        destination = "{absolute_path_to_directory}"

        etc.

    >

    <!--- Plus tard --->

    <cfimage action="resize" source="{absolute_path_to_directory}\#File.ServerFile#" height="300" width="200" name="resized">

    Dave Ferguson
    Participating Frequently
    March 16, 2017

    Hi,

    Your source code as a lot of interesting things going on.  Some of that may be causing the issues you are seeing.  Couple points of note for your code:

    • You can always use "/" as a file path separator regardless of operating system you are on.
    • The spaces inside your code make it difficult to read.  Spaces inside the pound signs are not necessary and may cause issues.
    • Unless you are outputing a var, or quoting it,  you don't need to put pound signs around it.  For example, the var set of myfile2.
    • The accept value had spaces in it that makes the value invalid. It should be "image/gif" not "image / gif".
    • When writing an image  you should cfimage action="write" after you resize the image.  Alternatively you can just add a destination to the resize action to save it automatically.

    Take a look at this blog post.  It shows how to upload and resize an image.  It does save the image to a database but you can ignore that part.

    http://www.dreamincode.net/forums/topic/254793-how-to-resize-and-add-an-image-to-a-database/

    HTH,

    --Dave

    ZNBAuthor
    Inspiring
    March 17, 2017

    Bonjour,

    La photo issu d'un iPhone fait 938 Ko !

    Mais le problème c'est que cela peut arriver souvent !

    Je vais essayer avec

    http://www.dreamincode.net/forums/topic/254793-how-to-resize-and-add-an-image-to-a-databas e

    Mais je trouve cela compliqué. Suis étonné qu'Adobe n'est pas intégré la fonction.

    Merci par avance

    NB : je comprends pour le blocage de sites

    ZNBAuthor
    Inspiring
    March 20, 2017

    Bonjour,

    J'ai essayé avec Dreamincode et cela plante toujours !

    Je ne comprends plus rien. Dois être maudit :-(

    Voici mon code :

    <span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()">

    <span class="google-src-text" style="text-align: left; direction: ltr;">

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <CFINCLUDE template="inc_init_admin.cfm">

    <CFINCLUDE template="inc_verif_var2.cfm">

    <title>Essai cfimage</title>

    <CFIF NOT IsDefined("mode")><cfset mode=""></CFIF>

    <cfset StrPath=ExpandPath( "../../" ) />

    <cfset taillemax=500000>

    </head>

    <body>

    <!--------------------------------- INSERT ------------------------------------------>

    <CFIF Mode IS "insert">

      <CFOUTPUT>

       <CFIF Find('/',StrPath) IS "/">

        <cfset sep="/">

       <CFELSE>

        <cfset sep="\">

       </CFIF>

      </CFOUTPUT>

      <cfif Picture neq "">

       <cftry>

        <cffile

         action="upload"

         filefield="Picture"

         Destination="#StrPath#zennetbuilder.com#sep#Solivres#sep#_cartes#sep#Images_upload"

         accept="image/jpeg, image/jpg, image/pjpeg"

         nameconflict="makeunique">

        <cfimage

         action = "info"

         source = "#StrPath#zennetbuilder.com#sep#Solivres#sep#_cartes#sep#images_upload#sep##serverfile#"

         structname = "Picturetest">

      

        <cfoutput>

         <cfset Picturewidth =  #Picturetest.width#>

         <cfset Pictureheight =  #Picturetest.height#>

         <cfset PictureSmallwidth = 200>

         <cfset PictureSmallHeight = #Pictureheight# / #Picturewidth# * #PictureSmallwidth#>

        </cfoutput>

        <cfimage action = "resize"

         height = "#Round(PictureSmallHeight)#"

         width="200"

         source="#StrPath#zennetbuilder.com#sep#Solivres#sep#_cartes#sep#Images_upload#sep##serverfile#"

         destination="#StrPath#zennetbuilder.com#sep##Solivres#sep#_cartes#sep#Images#sep##serverfile#"

        >

      

       </cftry>

      <cfelse>

       <CFQUERY name="Cartes" datasource="#session.dbname#">

        INSERT INTO cartes

        (PICTURE

        sitename)

        VALUES

        ('#SERVERFILE#'

        '#session.site#')

       </cfquery>

       <script language="Javascript">

        alert ("Votre fichier a été enregistré")

       </script>

       <cflocation url="cartes.cfm">

      </cfif>

    </CFIF>

    <!--------------------------------- Addpic ------------------------------------------>

    <CFIF Mode IS "">

        <table border="0" cellpadding="0" cellspacing="1" width="500" align="center">

      <cfform action="picture_add.cfm" name="AddPic" method="post" enctype="multipart/form-data">

       <tr>

        <td align="right" class="Copy" valign="top">Photo:</td>

        <td align="left" class="Copy" valign="top">

         <cfinput type="file" name="PICTURE" required="no">

        </td>

       </tr>

       <tr>

        <td> </td>

        <td align="left">

         <cfinput type="submit" name="Submit" value="Submit">

        </td>

       </tr>

            </cfform>

        </table>

    </CFIF>

    </body>

    </html>

    </span> !

    Merci par avance

    ZNBAuthor
    Inspiring
    March 15, 2017

    Bonjour,

    Est-il obligatoire de garder l'image originale ?

    Merci par avance

    WolfShade
    Legend
    March 15, 2017

    Bonjour,

    C'est tout à fait votre décision. Si vous avez besoin de conserver le fichier d'origine, le code que j'ai fourni conserverait à la fois l'original et les images redimensionnées. Si vous n'avez pas besoin de l'original, vous pouvez utiliser CFFILE action = "delete" pour supprimer l'original.

    Avec respect,

    ^_^

    ZNBAuthor
    Inspiring
    March 15, 2017

    Malgré toutes vos instructions, cela bloque :-(

    Voici mon code :

    <CFOUTPUT>
       <CFIF right(StrPath,1) IS "/">
        <cfset sep="/">
       <CFELSE>
        <cfset sep="\">
       </CFIF>

       <CFFILE
        Action="UPLOAD"
        Filefield="PhotoFile"
        Destination="#StrPath##session.site##sep#_cartes#sep#"
        Nameconflict="Overwrite"
        Accept="image/gif, image/jpg, image/jpeg"
       />
       <CFIF File.Filesize GT taillemax>
          
        <!--- Lire le fichier enregistré et le stocker dans une  variable CF nommée 'varName', le redimensionner, puis l'enregistrer sur  le disque dur---> 
       
        <CFFILE
         action="readBinary"
         file="#StrPath##session.site##sep#_cartes#sep##serverFileName#.#serverFileExt#"
         variable="varName"
        /> 
        
        <cfimage action="resize" source="#varName#" height="300" width="200" name="resized">
       
        <CFFILE 
         action="write"
         file="#StrPath##session.site##sep#_cartes#sep##varName#"
         output="#resized#"
         addnewline="no"
         fixnewline="no"
        /> 
        <CFELSE>
        <cfset myfile2=#File.ServerFile#>
       </CFIF>

    Encore merci !

    WolfShade
    Legend
    March 13, 2017

    Bonjour,

    According to the docs for CFIMAGE, you can use a variable to contain the image to be resized.  As haxtbh​ has pointed out, we really cannot understand what is wrong without seeing your code.  But if the image is being uploaded from a form, you need to use CFFILE to save it in a variable, then use CFIMAGE to resize the image.

    Selon les documents pour CFIMAGE, vous pouvez utiliser une variable pour contenir l'image à redimensionner. Comme haxtbh l'a souligné, nous ne pouvons vraiment pas comprendre ce qui ne va pas sans voir votre code. Mais si l'image est téléchargée à partir d'un formulaire, vous devez utiliser CFFILE pour l'enregistrer dans une variable, puis utiliser CFIMAGE pour redimensionner l'image.

    HTH,

    ^_^

    ZNBAuthor
    Inspiring
    March 13, 2017

    Avant tout merci pour vos réponses !

    Voici mon code :

    1ère partie avec un cfform :

    <INPUT type="file" name="PhotoFile" size="55" accept="image/jpg, image/jpeg, image/gif">

    2ème partie :

    <CFFILE

        Action="UPLOAD"

        Filefield="PhotoFile"

        Destination="#StrPath##session.site##sep#_cartes#sep#"

        Nameconflict="Overwrite"

        Accept="image/gif, image/jpg, image/jpeg"

       >

       <cfimage action="resize" source="File.ServerFile" height="300" width="200" name="resized">

    Rien d'extraordinaire !

    Cordialement

    WolfShade
    Legend
    March 13, 2017

    Your CFFILE is saving the uploaded image to a destination.  Use CFFILE to read the file you saved as a binary, give it a name, and use that for the CFIMAGE resize.

    OR, if you don't need the original file, you can skip saving it to a destination and save it in memory and use the memory to resize the file and save that to a destination.

    Votre CFFILE enregistre l'image téléchargée dans une destination. Utilisez CFFILE pour lire le fichier que vous avez enregistré en tant que binaire, donnez-lui un nom et utilisez-le pour le redimensionnement CFIMAGE.

    OU, si vous n'avez pas besoin du fichier d'origine, vous pouvez sauter l'enregistrement vers une destination et l'enregistrer en mémoire et utiliser la mémoire pour redimensionner le fichier et l'enregistrer dans une destination.

    HTH,

    ^_^

    Inspiring
    March 13, 2017

    Which version of Coldfusion are you using and what hotfix version is it?

    Can you give the full code you are using that gives you the error as well.