School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,007 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,002 people online right now. Registration is fast and FREE... Join Now!




Refresh Browser to see changes

 

Refresh Browser to see changes, After cropping an image must refresh browser to see result.

midasxl

4 Nov, 2009 - 10:45 AM
Post #1

D.I.C Head
**

Joined: 3 Dec, 2008
Posts: 125



Thanked: 1 times
My Contributions
Hello and thanks for your time; I hope I can explain this one clearly. I have an application that uploads an image, and then displays a thumbnail of the image via cfimage 'writeToBrowser'. The thumbnail image is wrapped in an anchor tag that opens a new page when clicked.

CODE

<a href="test_sid.cfm?ID=#getdetails.imgID#">
<cfimage id="pic" action="writeToBrowser"
source="#uploads##getdetails.image#"
height="110"
width="150"
border="0" />
</a>


When this image is clicked it takes you to 'test_sid.cfm' and passes the image id in the URL in order to display it full size on the new page.

CODE

<cfset variables.crop=#url.ID#>
<cfquery name="getPic" datasource="#datasource#">
SELECT *
FROM pics
WHERE imgID = #variables.crop#
</cfquery>

<form name="submitCrop" method="post" action="">
<cf_imageCropper imageCropperName="testimage" scriptSrc="#scriptSrc#" imgSrc="#uploadsRel##getPic.image#" />
<hr />
<input type="submit" name="submitCrop" value="Crop" class="buttons" style="font-weight:bold;" />
</form>


In the image source #uploadsRel# is a global variable path to the location of the queried image file: #getPic.image#

The form the image is wrapped in gets posted back to the same page and the following processing takes place.
The image is tested to see if a width and height exists, meaning the user has selected a crop area. The image is then read into an object and the x and y coordinates, along with the width and height are applied and then the new cropped image is written to a directory location. The new cropped image is then written to the browser. Another form is presented to save or go back and crop the image again.

CODE

<cfif structKeyExists(FORM,"submitCrop")>

<cfif testimage_height neq 0 and testimage_width neq 0>

<img class="icons" src="assets/images/tick_16.png" />Crop Successful!<br />

<cfimage action = "read" source="#uploads##getPic.image#" name="img" />
<cfset imageCrop(img, form.testimage_x1, form.testimage_y1, testimage_width, form.testimage_height)>

<cfscript>
ImageWrite(img,"#cumin##getPic.image#");
</cfscript>

<cfimage action="writeToBrowser" source="#img#" /></div>

<form name="saveCrop" method="post" action="">
<input type="submit" name="saveCrop" id="saveCrop" value="Save" class="buttons"/>
<input type="button" name="reload" value="Reload" class="buttons" onclick="java script:goback()">
</form>


OK, so far so good. Let's say the end user likes the cropped image and selects 'save'. The saveCrop occurs and the new cropped image overwrites the original uncropped image at the original location: #uploads##getPic.image#. The temporary cropped image is then deleted from its temp location.

CODE

<cfif structKeyExists(FORM,"saveCrop")>

<cfscript>
myImage=ImageRead("#cumin##getPic.image#");//location of temporary cropped image
ImageWrite(myImage,"#uploads##getPic.image#");
</cfscript>

<cffile action="delete" file="#cumin##getPic.image#"/>//delete temporary cropped image

<div id="successCrop">
<img class="icons" src="assets/images/tick_16.png" />Save Successful!<br />


After saving the new cropped image the page once again displays the image to the end user...

CODE

<cfscript>
myCrop=ImageRead("#uploads##getPic.image#");
</cfscript>

<cfimage action="writeToBrowser" source="#myCrop#" />


This successfully shows the newly cropped image. This all works very well. When I go back to the first page of thumbnails, the newly cropped image is displayed properly as a thumbnail. All is well. Here is the problem (finally).

When I once again click on the thumbnail it takes me to 'test_sid.cfm?ID=#getdetails.imgID#". What I see at this point is the full size ORIGINAL UNCROPPED IMAGE. Then when I hit the browser refresh button it shows me the NEWLY CROPPED full size image.

So this brings me to my question. How do I get the page to immediately show the newly cropped full size image without having to refresh the browser???

Thanks for any input!

Regards,
Mark

User is offlineProfile CardPM
+Quote Post


armyCoder

RE: Refresh Browser To See Changes

5 Nov, 2009 - 12:52 PM
Post #2

D.I.C Head
**

Joined: 2 Feb, 2009
Posts: 54



Thanked: 1 times
My Contributions
Mark,

Try the cfcache tag

Docs are here:
http://help.adobe.com/en_US/ColdFusion/9.0...22c24-7d5a.html



Make sure you use the 'flush' attribute. that should flush out the version that's getting hung up prior to a refresh.

This post has been edited by armyCoder: 5 Nov, 2009 - 12:52 PM
User is offlineProfile CardPM
+Quote Post

midasxl

RE: Refresh Browser To See Changes

6 Nov, 2009 - 07:53 AM
Post #3

D.I.C Head
**

Joined: 3 Dec, 2008
Posts: 125



Thanked: 1 times
My Contributions
armyCoder,
Thanks for the direction. I read up on the cfcache and flush suggestions. They seem to be the way to go in my situation. Where does this tag need to go?

CODE

<cfcache action="flush">


I placed it in the page that shows the actual image but not the cropped image without a refresh, and I also put it in my application.cfc page.

Neither avenue worked for me; after I crop the image, move away from the page and return it still shows the original uncropped image unless I hit refresh.

Am i putting this tag in the place it belongs?

Thanks for your help.
User is offlineProfile CardPM
+Quote Post

armyCoder

RE: Refresh Browser To See Changes

6 Nov, 2009 - 08:04 AM
Post #4

D.I.C Head
**

Joined: 2 Feb, 2009
Posts: 54



Thanked: 1 times
My Contributions
QUOTE(midasxl @ 6 Nov, 2009 - 08:53 AM) *


I placed it in the page that shows the actual image but not the cropped image without a refresh, and I also put it in my application.cfc page.



Can you show me how you coded it on that page? I'm thinking you either need to wrap the image tag in <cfcache> tags or do it right after the action is processed...
User is offlineProfile CardPM
+Quote Post

midasxl

RE: Refresh Browser To See Changes

6 Nov, 2009 - 08:47 AM
Post #5

D.I.C Head
**

Joined: 3 Dec, 2008
Posts: 125



Thanked: 1 times
My Contributions
Yes sir, here is the page that displays the image in question...

CODE


<body>

<cfset variables.crop=#url.ID#>
<cfquery name="getPic" datasource="#datasource#">
SELECT *
FROM pics
WHERE imgID = #variables.crop#
</cfquery>

<div id="header"></div>

<p class="links"><a class="nav" href="gallery.cfm">Return to image editor</a>
<a class="nav" href="FlexFileUpload.html">Return to upload manager</a>
<a class="nav" href="flash_gallery/photo.html">View Gallery</a></p>

<cfif structKeyExists(FORM,"submitCrop")>

<div id="toSaveCrop">
<cfif testimage_height neq 0 and testimage_width neq 0>

<img class="icons" src="assets/images/tick_16.png" />Crop Successful!<br />
<!---<img class="icons" src="assets/images/save_16.png" />Save New Image?--->
<hr />
<cfimage action = "read" source="#uploads##getPic.image#" name="img" />
<cfset imageCrop(img, form.testimage_x1, form.testimage_y1, testimage_width, form.testimage_height)>
        
                
<cfscript>
ImageWrite(img,"#cumin##getPic.image#");
</cfscript>

<div><cfimage action="writeToBrowser" source="#img#" /></div>
<hr />
<form name="saveCrop" method="post" action="">
<input type="submit" name="saveCrop" id="saveCrop" value="Save" class="buttons"/>
<input type="button" name="reload" value="Reload" class="buttons" onclick="java script:goback()">
</form>

<cfelse>

<div class="nope">You didn't select a crop area!!</div>

<form>
<input type="button" value="Reload Image" id="reload" class="buttons" onclick="java script:goback()">
</form>

</cfif>

</div>

<cfelseif structKeyExists(FORM,"saveCrop")>

<cfscript>
myImage=ImageRead("#cumin##getPic.image#");
ImageWrite(myImage,"#uploads##getPic.image#");
</cfscript>

<cffile action="delete" file="#cumin##getPic.image#"/>

<div id="successCrop">
<img class="icons" src="assets/images/tick_16.png" />Save Successful!<br />
<hr />

<cfscript>
myCrop=ImageRead("#uploads##getPic.image#");
</cfscript>

<cfimage action="writeToBrowser" source="#myCrop#" />

<hr />
<cfelse>
</div>

<cfcache action="flush">

<!---***Div of image to be cropped***--->

<p class="info"><img class="icon" src="images/web/gear_16.png" align="absmiddle">  Click and drag on image to define crop area; click 'Crop' to apply</p>
<div id="toCrop">

<form name="submitCrop" method="post" action="">
<cf_imageCropper imageCropperName="testimage" scriptSrc="#scriptSrc#" imgSrc="#uploadsRel##getPic.image#" />
<hr />
<input type="submit" name="submitCrop" value="Crop" class="buttons" style="font-weight:bold;" />
</form>
</div>

</cfif>

</body>
</html>


I also tried to wrap the elements that display the image like so...

CODE

<cfcache action="flush">
<!---******************Div of original image to be cropped**************************--->
<p class="info"><img class="icon" src="images/web/gear_16.png" align="absmiddle">  Click and drag on image to define crop area; click 'Crop' to apply</p>
<div id="toCrop">
<form name="submitCrop" method="post" action="">
<cf_imageCropper imageCropperName="testimage" scriptSrc="#scriptSrc#" imgSrc="#uploadsRel##getPic.image#" />
<hr />
<input type="submit" name="submitCrop" value="Crop" class="buttons" style="font-weight:bold;" />
</form>
</div>
</cfcache>


In this case nothing at all appeared on the page. Is this tag supposed to have a closing tag as well? Thanks for checking this all out for me!

This post has been edited by midasxl: 6 Nov, 2009 - 08:51 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:01AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month